util/wrapper: Add Static Client wrapper (#1685)

* util/wrapper: Add Static Client wrapper

* util/wrapper/static: pass address to stream too

* add static client wrapper tests

* server: fix error message spaces between words

* server/{rpc,grpc}: replace log.Error with log.Errorf

* server/grpc: fix log typo

* server/rpc: fix log typo

Co-authored-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
ben-toogood 2020-06-05 10:18:35 +01:00 committed by Vasiliy Tolstov
parent 8c937eabb9
commit f815eed7fd

View File

@ -87,7 +87,7 @@ func prepareEndpoint(method reflect.Method) *methodType {
contextType = mtype.In(1) contextType = mtype.In(1)
default: default:
if logger.V(logger.ErrorLevel, logger.DefaultLogger) { if logger.V(logger.ErrorLevel, logger.DefaultLogger) {
logger.Error("method", mname, "of", mtype, "has wrong number of ins:", mtype.NumIn()) logger.Errorf("method %v of %v has wrong number of ins: %v", mname, mtype, mtype.NumIn())
} }
return nil return nil
} }
@ -97,7 +97,7 @@ func prepareEndpoint(method reflect.Method) *methodType {
streamType := reflect.TypeOf((*server.Stream)(nil)).Elem() streamType := reflect.TypeOf((*server.Stream)(nil)).Elem()
if !argType.Implements(streamType) { if !argType.Implements(streamType) {
if logger.V(logger.ErrorLevel, logger.DefaultLogger) { if logger.V(logger.ErrorLevel, logger.DefaultLogger) {
logger.Error(mname, "argument does not implement Streamer interface:", argType) logger.Errorf("%v argument does not implement Streamer interface: %v", mname, argType)
} }
return nil return nil
} }
@ -107,14 +107,14 @@ func prepareEndpoint(method reflect.Method) *methodType {
// First arg need not be a pointer. // First arg need not be a pointer.
if !isExportedOrBuiltinType(argType) { if !isExportedOrBuiltinType(argType) {
if logger.V(logger.ErrorLevel, logger.DefaultLogger) { if logger.V(logger.ErrorLevel, logger.DefaultLogger) {
logger.Error(mname, "argument type not exported:", argType) logger.Errorf("%v argument type not exported: %v", mname, argType)
} }
return nil return nil
} }
if replyType.Kind() != reflect.Ptr { if replyType.Kind() != reflect.Ptr {
if logger.V(logger.ErrorLevel, logger.DefaultLogger) { if logger.V(logger.ErrorLevel, logger.DefaultLogger) {
logger.Error("method", mname, "reply type not a pointer:", replyType) logger.Errorf("method %v reply type not a pointer: %v", mname, replyType)
} }
return nil return nil
} }
@ -122,7 +122,7 @@ func prepareEndpoint(method reflect.Method) *methodType {
// Reply type must be exported. // Reply type must be exported.
if !isExportedOrBuiltinType(replyType) { if !isExportedOrBuiltinType(replyType) {
if logger.V(logger.ErrorLevel, logger.DefaultLogger) { if logger.V(logger.ErrorLevel, logger.DefaultLogger) {
logger.Error("method", mname, "reply type not exported:", replyType) logger.Errorf("method %v reply type not exported: %v", mname, replyType)
} }
return nil return nil
} }
@ -131,14 +131,14 @@ func prepareEndpoint(method reflect.Method) *methodType {
// Endpoint() needs one out. // Endpoint() needs one out.
if mtype.NumOut() != 1 { if mtype.NumOut() != 1 {
if logger.V(logger.ErrorLevel, logger.DefaultLogger) { if logger.V(logger.ErrorLevel, logger.DefaultLogger) {
logger.Error("method", mname, "has wrong number of outs:", mtype.NumOut()) logger.Errorf("method %v has wrong number of outs: %v", mname, mtype.NumOut())
} }
return nil return nil
} }
// The return type of the method must be error. // The return type of the method must be error.
if returnType := mtype.Out(0); returnType != typeOfError { if returnType := mtype.Out(0); returnType != typeOfError {
if logger.V(logger.ErrorLevel, logger.DefaultLogger) { if logger.V(logger.ErrorLevel, logger.DefaultLogger) {
logger.Error("method", mname, "returns", returnType.String(), "not error") logger.Errorf("method %v returns %v not error", mname, returnType.String())
} }
return nil return nil
} }
@ -156,7 +156,7 @@ func (server *rServer) register(rcvr interface{}) error {
s.rcvr = reflect.ValueOf(rcvr) s.rcvr = reflect.ValueOf(rcvr)
sname := reflect.Indirect(s.rcvr).Type().Name() sname := reflect.Indirect(s.rcvr).Type().Name()
if sname == "" { if sname == "" {
logger.Fatal("rpc: no service name for type", s.typ.String()) logger.Fatalf("rpc: no service name for type %v", s.typ.String())
} }
if !isExported(sname) { if !isExported(sname) {
s := "rpc Register: type " + sname + " is not exported" s := "rpc Register: type " + sname + " is not exported"