11package cmd
22
33import (
4+ " net/http"
5+
6+ " github.com/common-nighthawk/go-figure"
7+ " github.com/jzero-io/jzero/core/configcenter/subscriber"
48 " github.com/spf13/cobra"
59 configurator " github.com/zeromicro/go-zero/core/configcenter"
6- " github.com/jzero-io/jzero/core/configcenter/subscriber"
7- " github.com/zeromicro/go-zero/core/logx"
10+ " github.com/zeromicro/go-zero/core/logx"
811 " github.com/zeromicro/go-zero/core/service"
912 " github.com/zeromicro/go-zero/rest"
10- " github.com/common-nighthawk /go-figure "
13+ " github.com/zeromicro /go-zero/rest/httpx "
1114
1215 " {{ .Module }}/internal/config"
16+ " {{ .Module }}/internal/custom"
17+ " {{ .Module }}/internal/global"
1318 " {{ .Module }}/internal/middleware"
1419 " {{ .Module }}/internal/handler"
1520 " {{ .Module }}/internal/svc"
16- {{ if has " serverless_core " .Features }}" {{ .Module }}/plugins" {{end }}
21+ {{ if not .Serverless }}" {{ .Module }}/plugins" {{end }}
1722)
1823
19- // serverCmd represents the server command
2024var serverCmd = &cobra.Command {
2125 Use: " server" ,
2226 Short: " {{ .APP }} server" ,
@@ -25,41 +29,44 @@ var serverCmd = &cobra.Command{
2529 cc := configurator.MustNewConfigCenter [config.Config ](configurator.Config {
2630 Type: " yaml" ,
2731 }, subscriber.MustNewFsnotifySubscriber (cfgFile, subscriber.WithUseEnv (true)))
32+
2833 c, err := cc.GetConfig ()
2934 logx.Must (err)
3035
31- // set up logger
32- logx.Must (logx.SetUp (c.Log.LogConf ))
36+ // set up logger
37+ if err = logx.SetUp (c.Log.LogConf ); err != nil {
38+ logx.Must (err)
39+ }
3340
34- svcCtx := svc.NewServiceContext (cc)
35- run(svcCtx)
41+ // print banner
42+ printBanner(c)
43+ // print version
44+ printVersion()
45+
46+ svcCtx := svc.NewServiceContext (cc)
47+ svcCtx.Middleware = middleware.NewMiddleware ()
48+ global.ServiceContext = *svcCtx
49+ run(svcCtx)
3650 },
3751}
3852
3953func run(svcCtx *svc.ServiceContext ) {
40- c := svcCtx.MustGetConfig ()
54+ server := rest .MustNewServer ( svcCtx.MustGetConfig () .Rest.RestConf )
4155
42- server := rest .MustNewServer (c .Rest.RestConf )
43- middleware .Register (server )
56+ ctm := custom .New (server )
57+ ctm .Init ( )
4458
45- // server add api handlers
4659 handler.RegisterHandlers (server, svcCtx)
60+ middleware.Register (server)
4761
48- // server add custom routes
49- svcCtx.Custom.AddRoutes (server)
50-
51- {{ if has " serverless_core" .Features }}// load plugins features
52- plugins.LoadPlugins (server, *svcCtx){{end }}
62+ {{ if not .Serverless }}// load plugins
63+ plugins.LoadPlugins (server, svcCtx){{end }}
5364
5465 group := service.NewServiceGroup ()
5566 group.Add (server)
56- group.Add (svcCtx.Custom )
57-
58- printBanner(c)
59- printVersion()
67+ group.Add (ctm)
6068
61- logx.Infof (" Starting rest server at %s :%d ..." , c.Rest.Host , c.Rest.Port )
62- group.Start ()
69+ group.Start ()
6370}
6471
6572func printBanner(c config.Config ) {
0 commit comments