caarlos0/env

This commit is contained in:
Ed Minnix
2024-08-19 18:59:59 -04:00
parent f0f535b0e4
commit 8a7e378b40
3 changed files with 60 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
extensions:
- addsTo:
pack: codeql/go-all
extensible: sourceModel
data:
- ["github.com/caarlos0/env", "", False, "Parse", "", "", "Argument[0]", "environment", "manual"]
- ["github.com/caarlos0/env", "", False, "ParseAs", "", "", "ReturnValue[0]", "environment", "manual"]
- ["github.com/caarlos0/env", "", False, "ParseAsWithOptions", "", "", "ReturnValue[0]", "environment", "manual"]
- ["github.com/caarlos0/env", "", False, "ParseWithOptions", "", "", "Argument[0]", "environment", "manual"]
- addsTo:
pack: codeql/go-all
extensible: summaryModel
data:
- ["github.com/caarlos0/env", "", False, "Must", "", "", "Argument[0]", "ReturnValue", "value", "manual"]
- ["github.com/caarlos0/env", "", False, "ToMap", "", "", "Argument[0]", "ReturnValue", "taint", "manual"]

View File

@@ -2,6 +2,7 @@ package test
import (
"fmt"
"github.com/caarlos0/env"
"github.com/hashicorp/go-envparse"
"github.com/joho/godotenv"
"github.com/kelseyhightower/envconfig"
@@ -69,3 +70,19 @@ func envparseEnvironmentVariables() {
fmt.Printf("HOME: %s\n", envVars["HOME"])
}
func caarlos0EnvironmentVariables() {
type config struct {
Home string `env:"HOME"`
Port int `env:"PORT"`
}
cfg := config{}
env.Parse(&cfg) // $ source
fmt.Printf("HOME: %s\n", cfg.Home)
cfg = env.ParseAs[config]() // $ source
fmt.Printf("HOME: %s\n", cfg.Home)
}

View File

@@ -0,0 +1,28 @@
type Options struct {}
func Must[T any](t T, err error) T {
if err != nil {
panic(err)
}
return t
}
func Parse(v interface{}) error {
return nil
}
func ParseAs[T any]() (T, error) {
return nil, nil
}
func ParseAsWithOptions[T any](opts Options) (T, error) {
return nil, nil
}
func ParseWithOptions(v interface{}, opts Options) error {
return nil
}
func ToMap(env []string) map[string]string {
return nil
}