Skip to content

Commit

Permalink
Remove the "UsesContext" field from ServerInfo.
Browse files Browse the repository at this point in the history
The caller cannot do anything useful with this information, without more
details about what context encoding the server expects.
  • Loading branch information
creachadair committed Nov 26, 2021
1 parent 7ab9b38 commit 643e3dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
6 changes: 3 additions & 3 deletions opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 6 additions & 13 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -65,16 +64,14 @@ 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()),
allowP: opts.allowPush(),
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(),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"`
Expand Down

0 comments on commit 643e3dc

Please sign in to comment.