Skip to content

Commit

Permalink
make proto configurable
Browse files Browse the repository at this point in the history
Signed-off-by: zirain <[email protected]>
  • Loading branch information
zirain committed Oct 28, 2024
1 parent 28b1629 commit 00e75e6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/server/server_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const (
)

type server struct {
proto string
httpAddress string
grpcAddress string
grpcListenType grpcListenType
Expand Down Expand Up @@ -171,7 +172,7 @@ func (server *server) Start() {
logger.Warnf("Listening for debug on '%s'", server.debugAddress)
var err error
server.listenerMu.Lock()
server.debugListener.listener, err = reuseport.Listen("tcp", server.debugAddress)
server.debugListener.listener, err = reuseport.Listen(server.proto, server.debugAddress)
server.listenerMu.Unlock()

if err != nil {
Expand All @@ -187,7 +188,7 @@ func (server *server) Start() {
server.handleGracefulShutdown()

logger.Warnf("Listening for HTTP on '%s'", server.httpAddress)
list, err := reuseport.Listen("tcp", server.httpAddress)
list, err := reuseport.Listen(server.proto, server.httpAddress)
if err != nil {
logger.Fatalf("Failed to open HTTP listener: '%+v'", err)
}
Expand All @@ -209,7 +210,7 @@ func (server *server) startGrpc() {

switch server.grpcListenType {
case tcp:
lis, err = reuseport.Listen("tcp", server.grpcAddress)
lis, err = reuseport.Listen(server.proto, server.grpcAddress)
case unixDomainSocket:
lis, err = net.Listen("unix", server.grpcAddress)
default:
Expand Down Expand Up @@ -240,7 +241,7 @@ func newServer(s settings.Settings, name string, statsManager stats.Manager, loc
}

ret := new(server)

ret.proto = s.Proto
// setup stats
ret.store = statsManager.GetStatsStore()
ret.scope = ret.store.ScopeWithTags(name, s.ExtraTags)
Expand Down
1 change: 1 addition & 0 deletions src/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
)

type Settings struct {
Proto string `envconfig:"PROTO" default:"tcp"`
// runtime options
// This value shall be imported into unary server interceptor in order to enable chaining
GrpcUnaryInterceptor grpc.UnaryServerInterceptor
Expand Down

0 comments on commit 00e75e6

Please sign in to comment.