feat(goctl): Add api parser (#2585)

This commit is contained in:
anqiansong
2023-03-28 23:45:26 +08:00
committed by GitHub
parent 455a6c8f97
commit 50bc361430
59 changed files with 11633 additions and 6 deletions

View File

@@ -25,11 +25,14 @@ const (
GoctlDebug = "GOCTL_DEBUG"
GoctlCache = "GOCTL_CACHE"
GoctlVersion = "GOCTL_VERSION"
GoctlExperimental = "GOCTL_EXPERIMENTAL"
ProtocVersion = "PROTOC_VERSION"
ProtocGenGoVersion = "PROTOC_GEN_GO_VERSION"
ProtocGenGoGRPCVersion = "PROTO_GEN_GO_GRPC_VERSION"
envFileDir = "env"
envFileDir = "env"
ExperimentalOn = "on"
ExperimentalOff = "off"
)
// init initializes the goctl environment variables, the environment variables of the function are set in order,
@@ -56,6 +59,8 @@ func init() {
if value := existsEnv.GetStringOr(GoctlCache, ""); value != "" {
goctlEnv.SetKV(GoctlCache, value)
}
experimental:=existsEnv.GetOr(GoctlExperimental,ExperimentalOff)
goctlEnv.SetKV(GoctlExperimental,experimental)
}
if !goctlEnv.HasKey(GoctlHome) {
goctlEnv.SetKV(GoctlHome, defaultGoctlHome)
@@ -69,7 +74,12 @@ func init() {
goctlEnv.SetKV(GoctlCache, cacheDir)
}
if !goctlEnv.HasKey(GoctlExperimental){
goctlEnv.SetKV(GoctlExperimental, ExperimentalOff)
}
goctlEnv.SetKV(GoctlVersion, version.BuildVersion)
protocVer, _ := protoc.Version()
goctlEnv.SetKV(ProtocVersion, protocVer)
@@ -92,6 +102,10 @@ func GetOr(key, def string) string {
return goctlEnv.GetStringOr(key, def)
}
func UseExperimental() bool {
return GetOr(GoctlExperimental, ExperimentalOff) == ExperimentalOn
}
func readEnv(goctlHome string) *sortedmap.SortedMap {
envFile := filepath.Join(goctlHome, envFileDir)
data, err := os.ReadFile(envFile)