mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
feat: create polaris config (#2170)
* feat: create polaris config * feat: improve code * feat: modify config file path Co-authored-by: John Guo <john@johng.cn>
This commit is contained in:
32
example/config/polaris/boot/boot.go
Normal file
32
example/config/polaris/boot/boot.go
Normal file
@ -0,0 +1,32 @@
|
||||
package boot
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/contrib/config/polaris/v2"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
)
|
||||
|
||||
func init() {
|
||||
var (
|
||||
ctx = gctx.GetInitCtx()
|
||||
namespace = "default"
|
||||
fileGroup = "goframe"
|
||||
fileName = "config.yaml"
|
||||
path = "testdata/polaris.yaml"
|
||||
logDir = "/tmp/polaris/log"
|
||||
)
|
||||
// Create polaris Client that implements gcfg.Adapter.
|
||||
adapter, err := polaris.New(ctx, polaris.Config{
|
||||
Namespace: namespace,
|
||||
FileGroup: fileGroup,
|
||||
FileName: fileName,
|
||||
Path: path,
|
||||
LogDir: logDir,
|
||||
Watch: true,
|
||||
})
|
||||
if err != nil {
|
||||
g.Log().Fatalf(ctx, `%+v`, err)
|
||||
}
|
||||
// Change the adapter of default configuration instance.
|
||||
g.Cfg().SetAdapter(adapter)
|
||||
}
|
||||
20
example/config/polaris/main.go
Normal file
20
example/config/polaris/main.go
Normal file
@ -0,0 +1,20 @@
|
||||
package polaris
|
||||
|
||||
import (
|
||||
_ "github.com/gogf/gf/example/config/polaris/boot"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var ctx = gctx.GetInitCtx()
|
||||
|
||||
// Available checks.
|
||||
g.Dump(g.Cfg().Available(ctx))
|
||||
|
||||
// All key-value configurations.
|
||||
g.Dump(g.Cfg().Data(ctx))
|
||||
|
||||
// Retrieve certain value by key.
|
||||
g.Dump(g.Cfg().MustGet(ctx, "server.address"))
|
||||
}
|
||||
11
example/config/polaris/testdata/polaris.yaml
vendored
Normal file
11
example/config/polaris/testdata/polaris.yaml
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
global:
|
||||
serverConnector:
|
||||
addresses:
|
||||
- 183.47.111.80:8091
|
||||
config:
|
||||
configConnector:
|
||||
addresses:
|
||||
- 183.47.111.80:8093
|
||||
consumer:
|
||||
localCache:
|
||||
persistDir: "/tmp/polaris/backup"
|
||||
Reference in New Issue
Block a user