From 643e3dca3e837e622c6ebb250ef7a63d0d3adffb Mon Sep 17 00:00:00 2001 From: "M. J. Fromberger" Date: Fri, 26 Nov 2021 09:02:21 -0800 Subject: [PATCH] Remove the "UsesContext" field from ServerInfo. The caller cannot do anything useful with this information, without more details about what context encoding the server expects. --- opts.go | 6 +++--- server.go | 19 ++++++------------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/opts.go b/opts.go index cdb4109..505589d 100644 --- a/opts.go +++ b/opts.go @@ -95,13 +95,13 @@ func (o *ServerOptions) newContext() func() context.Context { type decoder = func(context.Context, string, json.RawMessage) (context.Context, json.RawMessage, error) -func (s *ServerOptions) decodeContext() (decoder, bool) { +func (s *ServerOptions) decodeContext() decoder { if s == nil || s.DecodeContext == nil { return func(ctx context.Context, method string, params json.RawMessage) (context.Context, json.RawMessage, error) { return ctx, params, nil - }, false + } } - return s.DecodeContext, true + return s.DecodeContext } func (s *ServerOptions) metrics() *metrics.M { diff --git a/server.go b/server.go index f133c7f..30efcdc 100644 --- a/server.go +++ b/server.go @@ -31,7 +31,6 @@ type Server struct { rpcLog RPCLogger // log RPC requests and responses here newctx func() context.Context // create a new base request context dectx decoder // decode context from request - expctx bool // whether to expect request context metrics *metrics.M // metrics collected during execution start time.Time // when Start was called builtin bool // whether built-in rpc.* methods are enabled @@ -65,7 +64,6 @@ func NewServer(mux Assigner, opts *ServerOptions) *Server { if mux == nil { panic("nil assigner") } - dc, exp := opts.decodeContext() s := &Server{ mux: mux, sem: semaphore.NewWeighted(opts.concurrency()), @@ -73,8 +71,7 @@ func NewServer(mux Assigner, opts *ServerOptions) *Server { log: opts.logFunc(), rpcLog: opts.rpcLog(), newctx: opts.newContext(), - dectx: dc, - expctx: exp, + dectx: opts.decodeContext(), mu: new(sync.Mutex), metrics: opts.metrics(), start: opts.startTime(), @@ -351,12 +348,11 @@ func (s *Server) invoke(base context.Context, h Handler, req *Request) (json.Raw // ServerInfo returns an atomic snapshot of the current server info for s. func (s *Server) ServerInfo() *ServerInfo { info := &ServerInfo{ - Methods: s.mux.Names(), - UsesContext: s.expctx, - StartTime: s.start, - Counter: make(map[string]int64), - MaxValue: make(map[string]int64), - Label: make(map[string]interface{}), + Methods: s.mux.Names(), + StartTime: s.start, + Counter: make(map[string]int64), + MaxValue: make(map[string]int64), + Label: make(map[string]interface{}), } s.metrics.Snapshot(metrics.Snapshot{ Counter: info.Counter, @@ -622,9 +618,6 @@ type ServerInfo struct { // The list of method names exported by this server. Methods []string `json:"methods,omitempty"` - // Whether this server understands context wrappers. - UsesContext bool `json:"usesContext"` - // Metric values defined by the evaluation of methods. Counter map[string]int64 `json:"counters,omitempty"` MaxValue map[string]int64 `json:"maxValue,omitempty"`