Skip to content

Commit

Permalink
style: reduce useless code and config (#129)
Browse files Browse the repository at this point in the history
* style(platform): change

* style(platform): reduce useless code and config

* style(platform): reduce useless code and config
  • Loading branch information
StellarisW authored Dec 22, 2023
1 parent 48f8324 commit 3c5dd4c
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 110 deletions.
3 changes: 1 addition & 2 deletions platform/manifest/config/config-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ app:
api:
host: '0.0.0.0' # api service listening host
port: 8089 # api service listening port
updateInterval: '3s' # interval that get service change from registry and push tasks change to agent services

agent:
addr: '0.0.0.0:11010' # agent service listening address
workerNum: 1 # worker num that process sync tasks. set to 0 to enable dynamic adjust worker num
workerNum: 1 # worker num that process sync tasks

registry:
builtin:
Expand Down
2 changes: 0 additions & 2 deletions platform/server/cmd/api/pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ type Manager struct {
agents []*service.Service

syncAgentServiceInterval time.Duration
syncRepositoryInterval time.Duration
syncIdlInterval time.Duration

daoManager *dao.Manager
Expand All @@ -70,7 +69,6 @@ func NewManager(appConf app.Config, daoManager *dao.Manager, dispatcher dispatch
agents: make([]*service.Service, 0),

syncAgentServiceInterval: appConf.GetSyncAgentServiceInterval(),
syncRepositoryInterval: appConf.GetSyncRepositoryInterval(),
syncIdlInterval: appConf.GetSyncIdlInterval(),

daoManager: daoManager,
Expand Down
13 changes: 1 addition & 12 deletions platform/server/shared/config/app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@ type Config struct {
Timezone string `mapstructure:"timezone"`
ProxyUrl string `mapstructure:"proxyUrl"`
SyncAgentServiceInterval string `mapstructure:"syncAgentServiceInterval"`
SyncRepositoryInterval string `mapstructure:"syncRepositoryInterval"`
SyncIdlInterval string `mapstructure:"syncIdlInterval"`
}

const (
defaultSyncAgentServiceInterval = 3 * time.Second
defaultSyncRepositoryInterval = 3 * time.Minute
defaultSyncAgentServiceInterval = 10 * time.Second
defaultSyncIdlInterval = 3 * time.Minute
)

Expand All @@ -56,15 +54,6 @@ func (conf *Config) GetSyncAgentServiceInterval() time.Duration {
return defaultSyncAgentServiceInterval
}

func (conf *Config) GetSyncRepositoryInterval() time.Duration {
duration, err := time.ParseDuration(conf.SyncIdlInterval)
if err == nil {
return duration
}

return defaultSyncRepositoryInterval
}

func (conf *Config) GetSyncIdlInterval() time.Duration {
duration, err := time.ParseDuration(conf.SyncIdlInterval)
if err == nil {
Expand Down
11 changes: 5 additions & 6 deletions platform/server/shared/config/internal/api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ import (
)

type Config struct {
Host string `mapstructure:"host"`
Port int `mapstructure:"port"`
Tracing TracerConf `mapstructure:"tracing"`
MetricsUrl string `mapstructure:"metricsUrl"`
Dispatcher dispatcher.Config `mapstructure:"dispatcher"`
UpdateInterval string `mapstructure:"updateInterval"`
Host string `mapstructure:"host"`
Port int `mapstructure:"port"`
Tracing TracerConf `mapstructure:"tracing"`
MetricsUrl string `mapstructure:"metricsUrl"`
Dispatcher dispatcher.Config `mapstructure:"dispatcher"`
}

type TracerConf struct {
Expand Down
6 changes: 5 additions & 1 deletion platform/server/shared/registry/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,10 @@ type BuiltinKitexRegistryClient struct {
updateInterval time.Duration
}

const (
defaultClientUpdateInterval = 10 * time.Second
)

func NewBuiltinKitexRegistryClient(addr string) (*BuiltinKitexRegistryClient, error) {
httpRes, err := http.Get(fmt.Sprintf("http://%s/api/ping", addr))
if err != nil {
Expand All @@ -375,7 +379,7 @@ func NewBuiltinKitexRegistryClient(addr string) (*BuiltinKitexRegistryClient, er
return &BuiltinKitexRegistryClient{
addr: addr,
stopChan: make(chan struct{}),
updateInterval: 10 * time.Second,
updateInterval: defaultClientUpdateInterval,
}, nil
}

Expand Down
69 changes: 0 additions & 69 deletions platform/server/template/agent/main_tpl.yaml

This file was deleted.

16 changes: 6 additions & 10 deletions platform/server/template/api/layout.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
layouts:
# 生成的 handler 的目录, 只有目录下有文件才会生成
- path: internal/biz/handler/
delims:
- ""
- ""
body: ""
# 生成的 model 的目录, 只有目录下有文件才会生成
- path: internal/biz/model/
delims:
- ""
- ""
body: ""
# 生成的 svc 的目录, 只有目录下有文件才会生成
- path: internal/svc/
delims:
- ""
- ""
body: ""

# .hz 文件,包含 hz 版本,是 hz 创建的项目的标志,不需要传渲染数据
# .hz file,contains hz version
- path: .hz
delims:
- '{{'
Expand All @@ -27,7 +24,6 @@ layouts:
// Code generated by hz. DO NOT EDIT.
hz version: {{.hzVersion}}
# ping 自带 ping 的 handler
- path: internal/biz/handler/ping.go
delims:
- ""
Expand Down Expand Up @@ -66,7 +62,7 @@ layouts:
"message": "pong",
})
}
# 自定义路由注册的文件
# customize router file
- path: router.go
delims:
- ""
Expand Down Expand Up @@ -103,7 +99,7 @@ layouts:
// your code ...
}
# 定义路由注册的文件,需要模板渲染数据{{.RouterPkgPath}}才能生成
# router file, need template render data{{.RouterPkgPath}} to generate
- path: router_gen.go
delims:
- ""
Expand Down Expand Up @@ -141,7 +137,7 @@ layouts:
customizedRegister(r)
}
# 默认中间件文件,不要修改
# default middleware file
- path: internal/biz/router/middleware.go
delims:
- ""
Expand Down Expand Up @@ -192,7 +188,7 @@ layouts:
return []app.HandlerFunc{}
}
# 默认路由注册文件,不要修改
# default router register file
- path: internal/biz/router/register.go
delims:
- ""
Expand Down Expand Up @@ -228,7 +224,7 @@ layouts:
g := r.Group("", rootMw()...)
}
# 服务上下文文件
# service context file
- path: internal/svc/servicecontext.go
delims:
- ""
Expand Down
22 changes: 14 additions & 8 deletions platform/server/template/api/package.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 以下数据都是 yaml marshal 得到的,所以可能看起来比较乱
layouts:
# path 只表示 handler.go 的模板,具体的 handler 路径由默认路径和 handler_dir 决定
# path only represent it's a template of handler.go
# handler file path is decided by handler_dir
- path: handler.go
delims:
- '{{'
Expand Down Expand Up @@ -76,7 +76,8 @@ layouts:
response.OkWithData(rCtx, res.Msg, res.Data)
}
{{end}}
# handler_single 表示单独的 handler 模板,用于 update 的时候更新每一个新增的 handler
# handler_single only represent it's a single handler template
# it's used to update every handler when use hz update
- path: handler_single.go
delims:
- '{{'
Expand Down Expand Up @@ -175,7 +176,8 @@ layouts:
Msg: successMsg{{.HttpMethod.Name}},
}
}
# path 只表示 router.go 的模板,其路径固定在:biz/router/namespace/
# path represent it's a template of router.go
# the file path is fixed in biz/router/namespace/
- path: router.go
delims:
- '{{'
Expand Down Expand Up @@ -239,7 +241,8 @@ layouts:
func Register(r *route.RouterGroup) {
{{template "G" .Router}}
}
# path 只表示 register.go 的模板,register 的路径固定为 biz/router/register.go
# path represent it's a template of register.go
# the file path is fixed in biz/router/register.go
- path: register.go
delims:
- ""
Expand Down Expand Up @@ -280,7 +283,8 @@ layouts:
- ""
- ""
body: ""
# path 只表示 middleware.go 的模板,middleware 的路径和 router.go 一样为:biz/router/namespace/
# path only represent it's a template of middleware.go
# the path of middleware and router.go is in biz/router/namespace/
- path: middleware.go
delims:
- '{{'
Expand Down Expand Up @@ -319,7 +323,8 @@ layouts:
{{- end}}
{{template "M" .Router}}
# middleware_single 表示单独的 middleware 模板,用于 update 的时候更新每一个新增的 middleware_single
# middleware_single represent it's a template of single middleware
# it will update every middleware_single when use hz update
- path: middleware_single.go
delims:
- '{{'
Expand All @@ -329,7 +334,8 @@ layouts:
// your code...
return nil
}
# path 只表示 client.go 的模板,client 代码的生成路径由用户指定"${client_dir}"
# path only represent it's a template of client.go
# client file generate path is specified by ${client_dir}"
- path: client.go
delims:
- '{{'
Expand Down

0 comments on commit 3c5dd4c

Please sign in to comment.