/
githubmirror
/
GoFrame
Обзор
Документация
Войти
/
githubmirror
/
GoFrame
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
os/gcfg/gcfg_z_example_test.go
66 строк
1 KB
John Guo
improve package gcfg
25 янв 2022, 15:43
25 янв 2022, 15:43
01b9fa8
Код
Авторство
О чём код?
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. // // This Source Code Form is subject to the terms of the MIT License. // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. package gcfg_test import ( "fmt" "os" "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/os/gcmd" "github.com/gogf/gf/v2/os/gctx" "github.com/gogf/gf/v2/os/genv" ) func ExampleConfig_GetWithEnv() { var ( key = `ENV_TEST` ctx = gctx.New() ) v, err := g.Cfg().GetWithEnv(ctx, key) if err != nil { panic(err) } fmt.Printf("env:%s\n", v) if err = genv.Set(key, "gf"); err != nil { panic(err) } v, err = g.Cfg().GetWithEnv(ctx, key) if err != nil { panic(err) } fmt.Printf("env:%s", v) // Output: // env: // env:gf } func ExampleConfig_GetWithCmd() { var ( key = `cmd.test` ctx = gctx.New() ) v, err := g.Cfg().GetWithCmd(ctx, key) if err != nil { panic(err) } fmt.Printf("cmd:%s\n", v) // Re-Initialize custom command arguments. os.Args = append(os.Args, fmt.Sprintf(`--%s=yes`, key)) gcmd.Init(os.Args...) // Retrieve the configuration and command option again. v, err = g.Cfg().GetWithCmd(ctx, key) if err != nil { panic(err) } fmt.Printf("cmd:%s", v) // Output: // cmd: // cmd:yes }