Skip to content

Commit

Permalink
feat(api): add addr grpc listen (#2491)
Browse files Browse the repository at this point in the history
Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
  • Loading branch information
yesnault authored and fsamin committed Mar 30, 2018
1 parent 0867d44 commit e2e9e6c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions engine/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ type Configuration struct {
UI string `toml:"ui" default:"http://localhost:2015"`
} `toml:"url" comment:"#####################\n CDS URLs Settings \n####################"`
HTTP struct {
Addr string `toml:"addr" default:"" commented:"true" comment:"Listen address without port, example: 127.0.0.1"`
Addr string `toml:"addr" default:"" commented:"true" comment:"Listen HTTP address without port, example: 127.0.0.1"`
Port int `toml:"port" default:"8081"`
SessionTTL int `toml:"sessionTTL" default:"60"`
} `toml:"http"`
GRPC struct {
Port int `toml:"port" default:"8082"`
Addr string `toml:"addr" default:"" commented:"true" comment:"Listen GRPC address without port, example: 127.0.0.1"`
Port int `toml:"port" default:"8082"`
} `toml:"grpc"`
Secrets struct {
Key string `toml:"key"`
Expand Down Expand Up @@ -549,12 +550,12 @@ func (a *API) Serve(ctx context.Context) error {

go func() {
//TLS is disabled for the moment. We need to serve TLS on HTTP too
if err := grpcInit(a.DBConnectionFactory, a.Config.GRPC.Port, false, "", ""); err != nil {
if err := grpcInit(a.DBConnectionFactory, a.Config.GRPC.Addr, a.Config.GRPC.Port, false, "", ""); err != nil {
log.Error("Cannot start GRPC server: %v", err)
}
}()

log.Info("Starting CDS API HTTP Server on port %d", a.Config.HTTP.Port)
log.Info("Starting CDS API HTTP Server on %s:%d", a.Config.HTTP.Addr, a.Config.HTTP.Port)
if err := s.ListenAndServe(); err != nil {
return fmt.Errorf("Cannot start HTTP server: %v", err)
}
Expand Down
6 changes: 3 additions & 3 deletions engine/api/grpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ import (
)

// grpcInit initialize all GRPC services
func grpcInit(dbConnectionFactory *database.DBConnectionFactory, port int, tls bool, certFile, keyFile string) error {
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
func grpcInit(dbConnectionFactory *database.DBConnectionFactory, addr string, port int, tls bool, certFile, keyFile string) error {
lis, err := net.Listen("tcp", fmt.Sprintf("%s:%d", addr, port))
if err != nil {
return err
}

log.Info("Starting GRPC services on port %d", port)
log.Info("Starting GRPC services on %s:%d", addr, port)

grpcHandlers := &grpcHandlers{
dbConnectionFactory: dbConnectionFactory,
Expand Down

0 comments on commit e2e9e6c

Please sign in to comment.