Skip to content

Commit

Permalink
feat(server): update server.go
Browse files Browse the repository at this point in the history
  • Loading branch information
jaronnie committed Oct 23, 2024
1 parent 81d2ffb commit ee2220f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 31 deletions.
37 changes: 9 additions & 28 deletions server/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@ package cmd

import (
"os"
"server/internal/config"
"server/internal/handler"
"server/internal/middleware"
"server/internal/svc"

"github.com/common-nighthawk/go-figure"
"github.com/spf13/cobra"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/core/proc"
"github.com/zeromicro/go-zero/core/service"
"github.com/zeromicro/go-zero/rest"
"golang.org/x/sync/errgroup"

"server/internal/config"
"server/internal/handler"
"server/internal/middleware"
"server/internal/svc"
)

// serverCmd represents the server command
Expand Down Expand Up @@ -56,29 +55,11 @@ func start(svcCtx *svc.ServiceContext) {

group := service.NewServiceGroup()
group.Add(server)
group.Add(svcCtx.Custom)

// shutdown listener
waitExit := proc.AddShutdownListener(svcCtx.Custom.Stop)

eg := errgroup.Group{}
eg.Go(func() error {
printBanner(svcCtx.Config)
logx.Infof("Starting rest server at %s:%d...", svcCtx.Config.Rest.Host, svcCtx.Config.Rest.Port)
group.Start()
return nil
})

// add custom start logic
eg.Go(func() error {
svcCtx.Custom.Start()
return nil
})

if err := eg.Wait(); err != nil {
panic(err)
}

waitExit()
printBanner(svcCtx.Config)
logx.Infof("Starting rest server at %s:%d...", svcCtx.Config.Rest.Host, svcCtx.Config.Rest.Port)
group.Start()
}

func printBanner(c config.Config) {
Expand Down
1 change: 0 additions & 1 deletion server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ require (
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.18.2
github.com/zeromicro/go-zero v1.7.2
golang.org/x/sync v0.8.0
gorm.io/driver/mysql v1.5.7
gorm.io/gorm v1.25.12
)
Expand Down
2 changes: 0 additions & 2 deletions server/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,6 @@ golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down

0 comments on commit ee2220f

Please sign in to comment.