Skip to content

Commit

Permalink
🔄 Sync from monorepo
Browse files Browse the repository at this point in the history
  • Loading branch information
mojo-machine[bot] committed Nov 21, 2023
1 parent 76821ec commit 0206087
Show file tree
Hide file tree
Showing 4 changed files with 234 additions and 227 deletions.
7 changes: 4 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ issues:
- linters:
- govet
text: "composites: go.mongodb.org/mongo-driver/bson/primitive.E struct literal uses unkeyed fields"

# TODO: fix these and remove
- { path: lib/crpc, text: ".*" }
- path: lib/crpc # TODO: resolve these
linters:
- gocognit
- nestif

linters-settings:
forbidigo:
Expand Down
22 changes: 12 additions & 10 deletions lib/crpc/example/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/http"
"time"

"github.com/go-chi/chi/v5"
"github.com/wearemojo/mojo-public-go/lib/clog"
Expand Down Expand Up @@ -47,29 +48,30 @@ func main() {

log := cfg.Logging.Configure(context.Background())

var es example.Service = &ExampleServer{}
var svc example.Service = &ExampleServer{}

// create a new RPC server
hw := crpc.NewServer(unsafeNoAuthentication)
rpc := crpc.NewServer(unsafeNoAuthentication)

// add logging middleware
hw.Use(crpc.Logger())
rpc.Use(crpc.Logger())

// register Ping and Greet (version 2017-11-08)
hw.Register("ping", "2017-11-08", nil, es.Ping)
hw.Register("greet", "2017-11-08", example.GreetRequestSchema, es.Greet)
rpc.Register("ping", "2017-11-08", nil, svc.Ping)
rpc.Register("greet", "2017-11-08", example.GreetRequestSchema, svc.Greet)

mux := chi.NewRouter()

mux.Use(request.Logger(log))
mux.With(request.StripPrefix("/v1")).Handle("/v1/*", rpc)

mux.With(request.StripPrefix("/v1")).Handle("/v1/*", hw)

s := &http.Server{Handler: mux}
httpServer := &http.Server{
Handler: mux,
ReadHeaderTimeout: 10 * time.Second,
}

log.WithField("addr", cfg.Server.Addr).Info("listening")

if err := cfg.Server.ListenAndServe(s); err != nil {
if err := cfg.Server.ListenAndServe(httpServer); err != nil {
log.WithError(err).Fatal("listen failed")
}
}
Expand Down
Loading

0 comments on commit 0206087

Please sign in to comment.