mirror of
https://github.com/Walter-Sparrow/lunar-tear.git
synced 2026-07-02 05:43:41 +03:00
Add --grpc-port support
This commit is contained in:
@@ -37,6 +37,7 @@ func (l loggingListener) Accept() (net.Conn, error) {
|
||||
|
||||
func startGRPC(
|
||||
host string,
|
||||
grpcPort int,
|
||||
octoURL string,
|
||||
userStore interface {
|
||||
store.UserRepository
|
||||
@@ -64,9 +65,10 @@ func startGRPC(
|
||||
sideStoryCatalog *masterdata.SideStoryCatalog,
|
||||
bigHuntCatalog *masterdata.BigHuntCatalog,
|
||||
) {
|
||||
lis, err := net.Listen("tcp", ":443")
|
||||
addr := fmt.Sprintf(":%d", grpcPort)
|
||||
lis, err := net.Listen("tcp", addr)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to listen on :443: %v", err)
|
||||
log.Fatalf("failed to listen on %s: %v", addr, err)
|
||||
}
|
||||
lis = loggingListener{Listener: lis}
|
||||
|
||||
@@ -77,6 +79,7 @@ func startGRPC(
|
||||
|
||||
registerServices(grpcServer,
|
||||
host,
|
||||
grpcPort,
|
||||
octoURL,
|
||||
userStore,
|
||||
questEngine,
|
||||
@@ -104,8 +107,8 @@ func startGRPC(
|
||||
|
||||
reflection.Register(grpcServer)
|
||||
|
||||
log.Printf("gRPC server listening on :443")
|
||||
log.Printf("client host address: %s:443", host)
|
||||
log.Printf("gRPC server listening on %s", addr)
|
||||
log.Printf("client host address: %s:%d", host, grpcPort)
|
||||
|
||||
if err := grpcServer.Serve(lis); err != nil {
|
||||
log.Fatalf("failed to serve: %v", err)
|
||||
@@ -115,6 +118,7 @@ func startGRPC(
|
||||
func registerServices(
|
||||
srv *grpc.Server,
|
||||
host string,
|
||||
grpcPort int,
|
||||
octoURL string,
|
||||
userStore interface {
|
||||
store.UserRepository
|
||||
@@ -145,7 +149,7 @@ func registerServices(
|
||||
pb.RegisterBannerServiceServer(srv, service.NewBannerServiceServer(gachaEntries))
|
||||
pb.RegisterUserServiceServer(srv, service.NewUserServiceServer(userStore, userStore))
|
||||
pb.RegisterBattleServiceServer(srv, service.NewBattleServiceServer(userStore, userStore))
|
||||
pb.RegisterConfigServiceServer(srv, service.NewConfigServiceServer(host, int32(443), octoURL))
|
||||
pb.RegisterConfigServiceServer(srv, service.NewConfigServiceServer(host, int32(grpcPort), octoURL))
|
||||
pb.RegisterDataServiceServer(srv, service.NewDataServiceServer(userStore, userStore))
|
||||
pb.RegisterTutorialServiceServer(srv, service.NewTutorialServiceServer(userStore, userStore, questEngine))
|
||||
pb.RegisterGachaServiceServer(srv, service.NewGachaServiceServer(userStore, userStore, gachaEntries, gachaHandler))
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
|
||||
func main() {
|
||||
httpPort := flag.Int("http-port", 8080, "HTTP server port (Octo API)")
|
||||
grpcPort := flag.Int("grpc-port", 443, "gRPC server port")
|
||||
host := flag.String("host", "127.0.0.1", "hostname the client will connect to")
|
||||
dbPath := flag.String("db", "db/game.db", "SQLite database path")
|
||||
flag.Parse()
|
||||
@@ -165,6 +166,7 @@ func main() {
|
||||
|
||||
startGRPC(
|
||||
*host,
|
||||
*grpcPort,
|
||||
octoURL,
|
||||
userStore,
|
||||
questHandler,
|
||||
|
||||
@@ -5,10 +5,11 @@ services:
|
||||
environment:
|
||||
LUNAR_HOST: 127.0.0.1
|
||||
LUNAR_HTTP_PORT: 8080
|
||||
LUNAR_GRPC_PORT: 8003
|
||||
volumes:
|
||||
- ./assets:/opt/lunar-tear/assets
|
||||
- ./db:/opt/lunar-tear/db
|
||||
ports:
|
||||
- 443:443 # grpc, hardcoded by the client, not configurable
|
||||
- 8003:8003
|
||||
- 8080:8080
|
||||
|
||||
|
||||
@@ -4,4 +4,4 @@ set -e
|
||||
mkdir -p db
|
||||
goose -dir migrations sqlite3 db/game.db up
|
||||
|
||||
exec ./lunar-tear --host "${LUNAR_HOST}" --http-port "${LUNAR_HTTP_PORT}"
|
||||
exec ./lunar-tear --host "${LUNAR_HOST}" --http-port "${LUNAR_HTTP_PORT}" --grpc-port "${LUNAR_GRPC_PORT:-443}"
|
||||
|
||||
Reference in New Issue
Block a user