Skip to content

Commit

Permalink
Merge pull request stack-labs#21 from micro-in-cn/agent
Browse files Browse the repository at this point in the history
agent-api 支持参数/环境变量设置 cache size
  • Loading branch information
Allenxuxu authored Apr 10, 2020
2 parents ee35d61 + e3c5ba1 commit a2cac40
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion agent-api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,27 @@ import (
"github.com/micro-in-cn/XConf/agent-api/config"
"github.com/micro-in-cn/XConf/agent-api/handler"
pconfig "github.com/micro-in-cn/XConf/proto/config"
"github.com/micro/cli"
"github.com/micro/go-micro/web"
)

func main() {
var cacheSize int

service := web.NewService(
web.Name("go.micro.api.agent"),
web.Flags(
cli.IntFlag{
Name: "cache_size",
Usage: "cache size (k)",
EnvVar: "XCONF_CACHE_SIZE",
Value: 1024 * 1024,
Destination: nil,
},
),
web.Action(func(context *cli.Context) {
cacheSize = context.Int("cache_size")
}),
)

if err := service.Init(); err != nil {
Expand All @@ -19,7 +34,7 @@ func main() {

client := pconfig.NewConfigService("go.micro.srv.config", service.Options().Service.Client())

config.Init(client, 1024*1024)
config.Init(client, cacheSize*1024)
router := Router()
service.Handle("/", router)

Expand Down

0 comments on commit a2cac40

Please sign in to comment.