From 230a63771d6e0c4e7d2e0a9fefce4a02f484e41e Mon Sep 17 00:00:00 2001 From: Windfarer Date: Fri, 27 Sep 2019 23:49:19 +0800 Subject: [PATCH 1/5] update doc (#361) --- doc/wiki-cn/config-paladin.md | 75 +++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 34 deletions(-) diff --git a/doc/wiki-cn/config-paladin.md b/doc/wiki-cn/config-paladin.md index 0becb02cf..28d8c1cc9 100644 --- a/doc/wiki-cn/config-paladin.md +++ b/doc/wiki-cn/config-paladin.md @@ -46,9 +46,10 @@ func TestMain(t *testing.M) { ### example main ```go -# main.go +// main.go func main() { - # 初始化paladin + flag.Parse() + // 初始化paladin if err := paladin.Init(); err != nil { panic(err) } @@ -58,28 +59,31 @@ func main() { ``` ### example HTTP/gRPC -```go +```toml # http.toml [server] addr = "0.0.0.0:9000" timeout = "1s" -# server.go +``` + +```go +// server.go func NewServer() { - # 默认配置用nil,这时读取HTTP/gRPC构架中的flag或者环境变量(可能是docker注入的环境变量,默认端口:8000/9000) - engine := bm.DefaultServer(nil) - - # 除非自己要替换了配置,用http.toml - var bc struct { - Server *bm.ServerConfig - } - if err = paladin.Get("http.toml").UnmarshalTOML("server", &bc); err != nil { - // 不存在时,将会为nil使用默认配置 - if err != paladin.ErrNotExist { - panic(err) - } - } - engine := bm.DefaultServer(conf) + // 默认配置用nil,这时读取HTTP/gRPC构架中的flag或者环境变量(可能是docker注入的环境变量,默认端口:8000/9000) + engine := bm.DefaultServer(nil) + + // 除非自己要替换了配置,用http.toml + var bc struct { + Server *bm.ServerConfig + } + if err := paladin.Get("http.toml").UnmarshalTOML(&bc); err != nil { + // 不存在时,将会为nil使用默认配置 + if err != paladin.ErrNotExist { + panic(err) + } + } + engine := bm.DefaultServer(bc.Server) } ``` @@ -87,25 +91,28 @@ func NewServer() { ```go # service.go type Service struct { - ac *paladin.Map + ac *paladin.Map } + func New() *Service { - # paladin.Map 通过atomic.Value支持自动热加载 - var ac = new(paladin.TOML) - if err := paladin.Watch("application.toml", ac); err != nil { - panic(err) - } - s := &Service{ - ac : ac; - } - return s + // paladin.Map 通过atomic.Value支持自动热加载 + var ac = new(paladin.TOML) + if err := paladin.Watch("application.toml", ac); err != nil { + panic(err) + } + s := &Service{ + ac: ac, + } + return s } + func (s *Service) Test() { - switch, err := s.ac.Bool("switch") - if err != nil { - // TODO - } - # or use default value - switch := paladin.Bool(s.ac.Value("switch"), false) + sw, err := s.ac.Get("switch").Bool() + if err != nil { + // TODO + } + + // or use default value + sw := paladin.Bool(s.ac.Get("switch"), false) } ``` From 0fc38dd40f29fb1fdc410841558ff96e5b942d7e Mon Sep 17 00:00:00 2001 From: sfw Date: Sat, 28 Sep 2019 17:36:50 +0800 Subject: [PATCH 2/5] improve get gopaths --- tool/kratos-protoc/protoc.go | 9 +-------- tool/kratos/tool.go | 9 +-------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/tool/kratos-protoc/protoc.go b/tool/kratos-protoc/protoc.go index accd6c518..57b3bec19 100644 --- a/tool/kratos-protoc/protoc.go +++ b/tool/kratos-protoc/protoc.go @@ -144,14 +144,7 @@ func latestKratos() (string, error) { } func gopath() (gp string) { - var gopaths []string - - switch runtime.GOOS { - case "windows": - gopaths = strings.Split(os.Getenv("GOPATH"), ";") - default: - gopaths = strings.Split(os.Getenv("GOPATH"), ":") - } + gopaths := strings.Split(os.Getenv("GOPATH"), string(filepath.ListSeparator)) if len(gopaths) == 1 && gopaths[0] != "" { return gopaths[0] diff --git a/tool/kratos/tool.go b/tool/kratos/tool.go index 3b410d4c9..cc7f0c258 100644 --- a/tool/kratos/tool.go +++ b/tool/kratos/tool.go @@ -186,14 +186,7 @@ func (t Tool) installed() bool { } func gopath() (gp string) { - var gopaths []string - - switch runtime.GOOS { - case "windows": - gopaths = strings.Split(os.Getenv("GOPATH"), ";") - default: - gopaths = strings.Split(os.Getenv("GOPATH"), ":") - } + gopaths := strings.Split(os.Getenv("GOPATH"), string(filepath.ListSeparator)) if len(gopaths) == 1 && gopaths[0] != "" { return gopaths[0] From 792f4374bbe0cccba9d462cec57e1976845e0a66 Mon Sep 17 00:00:00 2001 From: Tony Date: Sun, 29 Sep 2019 10:07:41 +0800 Subject: [PATCH 3/5] fix new path --- tool/kratos/new.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tool/kratos/new.go b/tool/kratos/new.go index cd7f2a5ca..2b2b08ad7 100644 --- a/tool/kratos/new.go +++ b/tool/kratos/new.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "path" + "path/filepath" "github.com/urfave/cli" ) @@ -25,6 +26,7 @@ func runNew(ctx *cli.Context) error { pwd, _ := os.Getwd() p.Path = path.Join(pwd, p.Name) } + p.Path = filepath.FromSlash(p.Path) // Create a project if err := create(); err != nil { return err From ccb63f06a379b38cb27091c9878557c0e7b7d9a5 Mon Sep 17 00:00:00 2001 From: Arthur Date: Mon, 30 Sep 2019 13:45:10 +0800 Subject: [PATCH 4/5] fix: fixconfig --- pkg/naming/discovery/discovery.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/naming/discovery/discovery.go b/pkg/naming/discovery/discovery.go index d5c24f9f9..b74061ef7 100644 --- a/pkg/naming/discovery/discovery.go +++ b/pkg/naming/discovery/discovery.go @@ -102,7 +102,7 @@ type appInfo struct { } func fixConfig(c *Config) error { - if len(c.Nodes) == 0 { + if len(c.Nodes) == 0 && env.DiscoveryNodes != "" { c.Nodes = strings.Split(env.DiscoveryNodes, ",") } if c.Region == "" { From 3f88ce925a70a960b1c2f1cdd40957111cbff84c Mon Sep 17 00:00:00 2001 From: realityone Date: Tue, 8 Oct 2019 10:53:48 +0800 Subject: [PATCH 5/5] integrate automaxprocs in project template --- tool/kratos/template.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tool/kratos/template.go b/tool/kratos/template.go index 2befe32fb..98665ebb7 100644 --- a/tool/kratos/template.go +++ b/tool/kratos/template.go @@ -76,6 +76,8 @@ import ( "{{.Name}}/internal/service" "github.com/bilibili/kratos/pkg/conf/paladin" "github.com/bilibili/kratos/pkg/log" + + _ "go.uber.org/automaxprocs" ) func main() { @@ -127,6 +129,8 @@ import ( "{{.Name}}/internal/service" "github.com/bilibili/kratos/pkg/conf/paladin" "github.com/bilibili/kratos/pkg/log" + + _ "go.uber.org/automaxprocs" ) func main() {