Skip to content

Commit

Permalink
chore(pkg/server/webserver): Use ImmuService directly instead of a gR…
Browse files Browse the repository at this point in the history
…PC client

Note that the generated gateway code has a comment about this:

// RegisterImmuServiceHandlerServer registers the http handlers for service ImmuService to "mux".
// UnaryRPC     :call ImmuServiceServer directly.
// StreamingRPC :currently unsupported pending grpc/grpc-go#906.
// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterImmuServiceHandlerFromEndpoint instead.
func RegisterImmuServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server ImmuServiceServer) error {
  • Loading branch information
dmacvicar committed May 4, 2021
1 parent afce982 commit 263632e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
4 changes: 2 additions & 2 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ func (s *ImmuServer) setUpMetricsServer() error {

func (s *ImmuServer) setUpWebServer() error {
server, err := StartWebServer(
s.Options.WebBind(),
s.Options.GprcConnectAddr(),
s.Options.WebBind(),
s,
s.Logger,
)
if err != nil {
Expand Down
8 changes: 3 additions & 5 deletions pkg/server/webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@ import (
"github.com/codenotary/immudb/pkg/logger"
"github.com/codenotary/immudb/webconsole"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"google.golang.org/grpc"
"net/http"
)

func StartWebServer(addr string, grpcAddr string, l logger.Logger) (*http.Server, error) {
func StartWebServer(addr string, s schema.ImmuServiceServer, l logger.Logger) (*http.Server, error) {
proxyMux := runtime.NewServeMux()
opts := []grpc.DialOption{grpc.WithInsecure()}
err := schema.RegisterImmuServiceHandlerFromEndpoint(context.Background(), proxyMux, grpcAddr, opts)
err := schema.RegisterImmuServiceHandlerServer(context.Background(), proxyMux, s)
if err != nil {
return nil, err
}

webMux := http.NewServeMux()
webMux.Handle("/api/", http.StripPrefix("/api", proxyMux))
l.Infof("Web API server enabled on %s/api. Managing immudb via %s", addr, grpcAddr)
l.Infof("Web API server enabled on %s/api.", addr)

err = webconsole.SetupWebconsole(webMux, l, addr)
if err != nil {
Expand Down

0 comments on commit 263632e

Please sign in to comment.