-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1368a19
commit 2ff3bc3
Showing
12 changed files
with
818 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
GRPC_PROTO_PATH=./grpc/pb | ||
PROTO_FILE=$(GRPC_PROTO_PATH)/snow.proto | ||
.PHONY: gen-proto | ||
go-proto: | ||
protoc --go_out=plugins=grpc:. $(PROTO_FILE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package commands | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/urfave/cli" | ||
"golang.org/x/sync/errgroup" | ||
|
||
gsrv "github.com/CyrivlClth/snowserver/grpc/server" | ||
hsrv "github.com/CyrivlClth/snowserver/http/server" | ||
) | ||
|
||
var ( | ||
grpcPort int | ||
httpPort int | ||
) | ||
|
||
var ServerFlags = []cli.Flag{ | ||
cli.IntFlag{ | ||
Name: "gp", | ||
Usage: "指定grpc服务的端口号,默认50051", | ||
Value: 50051, | ||
Destination: &grpcPort, | ||
}, | ||
cli.IntFlag{ | ||
Name: "hp", | ||
Usage: "指定http服务的端口号,默认50051", | ||
Value: 8080, | ||
Destination: &httpPort, | ||
}, | ||
cli.BoolFlag{ | ||
Name: "d", | ||
Usage: "指定服务后台运行", | ||
}, | ||
} | ||
|
||
var ServerCommand = cli.Command{ | ||
Name: "server", | ||
Usage: "运行grpc和http服务", | ||
Action: RunAllAction, | ||
Subcommands: []cli.Command{ | ||
{ | ||
Name: "grpc", | ||
Usage: "仅运行grpc服务", | ||
Action: RunGrpcAction, | ||
}, | ||
{ | ||
Name: "http", | ||
Usage: "仅运行http服务", | ||
Action: RunHttpAction, | ||
}, | ||
}, | ||
} | ||
|
||
func RunAllAction(c *cli.Context) error { | ||
g := errgroup.Group{} | ||
g.Go(func() error { | ||
return RunGrpcAction(c) | ||
}) | ||
|
||
g.Go(func() error { | ||
return RunHttpAction(c) | ||
}) | ||
|
||
return g.Wait() | ||
} | ||
|
||
func RunGrpcAction(c *cli.Context) error { | ||
return gsrv.Run(fmt.Sprintf(":%d", grpcPort)) | ||
} | ||
|
||
func RunHttpAction(c *cli.Context) error { | ||
gin.SetMode(gin.ReleaseMode) | ||
return hsrv.Run(fmt.Sprintf(":%d", httpPort)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/CyrivlClth/snowflake" | ||
"github.com/CyrivlClth/snowflake/idgen" | ||
) | ||
|
||
var idGen idgen.IDGenerator | ||
|
||
// Init 初始化config | ||
func Init(workerID, dataCenterID int64) (err error) { | ||
idGen, err = snowflake.New(workerID, dataCenterID) | ||
return | ||
} | ||
|
||
// IDGenerator 获取全局ID生成器 | ||
func IDGenerator() idgen.IDGenerator { | ||
return idGen | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package client |
Oops, something went wrong.