30 lines
588 B
Go
30 lines
588 B
Go
package config
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/gogf/gf/v2/encoding/gbase64"
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
"github.com/gogf/gf/v2/os/gcfg"
|
|
"google.golang.org/grpc/metadata"
|
|
)
|
|
|
|
func All(ctx context.Context) *gcfg.Config {
|
|
return g.Cfg()
|
|
}
|
|
|
|
func Api(ctx context.Context) *gcfg.Config {
|
|
md, ok := metadata.FromIncomingContext(ctx)
|
|
c := md.Get("x-cfg-api")
|
|
if ok && len(c) > 0 {
|
|
b, _ := gbase64.DecodeToString(c[0])
|
|
a, err := gcfg.NewAdapterContent(b)
|
|
if err != nil {
|
|
g.Log("config with api").Error(ctx, err)
|
|
}
|
|
return gcfg.NewWithAdapter(a)
|
|
}
|
|
|
|
return g.Cfg("api")
|
|
}
|