-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: disable shared lib install at the code level (#259)
Signed-off-by: peefy <xpf6677@163.com>
- Loading branch information
Showing
6 changed files
with
134 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package env | ||
|
||
import ( | ||
"os" | ||
"strconv" | ||
"sync" | ||
) | ||
|
||
var ( | ||
once sync.Once | ||
mu sync.Mutex | ||
env *EnvSettings | ||
) | ||
|
||
// EnvSettings represents environment settings for the KCL Go SDK. | ||
type EnvSettings struct { | ||
LibHome string | ||
DisableInstallArtifact bool | ||
DisableUseArtifactInPath bool | ||
} | ||
|
||
// Instance returns a singleton instance of EnvSettings. | ||
func instance() *EnvSettings { | ||
once.Do(func() { | ||
env = &EnvSettings{ | ||
LibHome: os.Getenv("KCL_LIB_HOME"), | ||
DisableInstallArtifact: envBoolOr("KCL_GO_DISABLE_INSTALL_ARTIFACT", false), | ||
DisableUseArtifactInPath: envBoolOr("KCL_GO_DISABLE_ARTIFACT_IN_PATH", false), | ||
} | ||
}) | ||
return env | ||
} | ||
|
||
// GetLibHome returns the LibHome value from the singleton instance of EnvSettings. | ||
func GetLibHome() string { | ||
return instance().LibHome | ||
} | ||
|
||
// SetLibHome sets the LibHome value in the singleton instance of EnvSettings. | ||
func SetLibHome(value string) { | ||
mu.Lock() | ||
defer mu.Unlock() | ||
instance().LibHome = value | ||
} | ||
|
||
// SetDisableInstallArtifact sets the DisableInstallArtifact value in the singleton instance of EnvSettings. | ||
func SetDisableInstallArtifact(value bool) { | ||
mu.Lock() | ||
defer mu.Unlock() | ||
instance().DisableInstallArtifact = value | ||
} | ||
|
||
// GetDisableInstallArtifact returns the DisableInstallArtifact value from the singleton instance of EnvSettings. | ||
func GetDisableInstallArtifact() bool { | ||
return instance().DisableInstallArtifact | ||
} | ||
|
||
// GetDisableUseArtifactInPath returns the DisableUseArtifactInPath value from the singleton instance of EnvSettings. | ||
func GetDisableUseArtifactInPath() bool { | ||
return instance().DisableUseArtifactInPath | ||
} | ||
|
||
// SetDisableUseArtifactInPath sets the DisableUseArtifactInPath value in the singleton instance of EnvSettings. | ||
func SetDisableUseArtifactInPath(value bool) { | ||
mu.Lock() | ||
defer mu.Unlock() | ||
instance().DisableUseArtifactInPath = value | ||
} | ||
|
||
// envOr returns the value of the specified environment variable, or the | ||
// default value if it does not exist. | ||
func envOr(name, def string) string { | ||
if v, ok := os.LookupEnv(name); ok { | ||
return v | ||
} | ||
return def | ||
} | ||
|
||
// envBoolOr returns the boolean value of the specified environment variable, | ||
// or the default value if it does not exist. | ||
func envBoolOr(name string, def bool) bool { | ||
if name == "" { | ||
return def | ||
} | ||
envVal := envOr(name, strconv.FormatBool(def)) | ||
ret, err := strconv.ParseBool(envVal) | ||
if err != nil { | ||
return def | ||
} | ||
return ret | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,21 @@ | ||
// Copyright The KCL Authors. All rights reserved. | ||
|
||
package utils | ||
|
||
import "os" | ||
|
||
func FileExists(path string) bool { | ||
fi, err := os.Lstat(path) | ||
if err != nil || fi.IsDir() { | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
func DirExists(path string) bool { | ||
fi, err := os.Lstat(path) | ||
if err != nil || !fi.IsDir() { | ||
return false | ||
} | ||
return true | ||
} |