More linting fun
This commit is contained in:
parent
2f50c74f41
commit
bfe20d81d0
@ -11,7 +11,7 @@ func TestBroker(t *testing.T) {
|
|||||||
b := NewBroker()
|
b := NewBroker()
|
||||||
|
|
||||||
if err := b.Connect(); err != nil {
|
if err := b.Connect(); err != nil {
|
||||||
t.Fatal("Unexpected connect error %v", err)
|
t.Fatalf("Unexpected connect error %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
topic := "test"
|
topic := "test"
|
||||||
|
@ -42,7 +42,6 @@ func (j *jsonCodec) Write(m *codec.Message, b interface{}) error {
|
|||||||
default:
|
default:
|
||||||
return fmt.Errorf("Unrecognised message type: %v", m.Type)
|
return fmt.Errorf("Unrecognised message type: %v", m.Type)
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *jsonCodec) ReadHeader(m *codec.Message, mt codec.MessageType) error {
|
func (j *jsonCodec) ReadHeader(m *codec.Message, mt codec.MessageType) error {
|
||||||
|
@ -19,29 +19,29 @@ func TestErrors(t *testing.T) {
|
|||||||
ne := New(e.Id, e.Detail, e.Code)
|
ne := New(e.Id, e.Detail, e.Code)
|
||||||
|
|
||||||
if e.Error() != ne.Error() {
|
if e.Error() != ne.Error() {
|
||||||
t.Fatal("Expected %s got %s", e.Error(), ne.Error())
|
t.Fatalf("Expected %s got %s", e.Error(), ne.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
pe := Parse(ne.Error())
|
pe := Parse(ne.Error())
|
||||||
|
|
||||||
if pe == nil {
|
if pe == nil {
|
||||||
t.Fatal("Expected error got nil %v", pe)
|
t.Fatalf("Expected error got nil %v", pe)
|
||||||
}
|
}
|
||||||
|
|
||||||
if pe.Id != e.Id {
|
if pe.Id != e.Id {
|
||||||
t.Fatal("Expected %s got %s", e.Id, pe.Id)
|
t.Fatalf("Expected %s got %s", e.Id, pe.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
if pe.Detail != e.Detail {
|
if pe.Detail != e.Detail {
|
||||||
t.Fatal("Expected %s got %s", e.Detail, pe.Detail)
|
t.Fatalf("Expected %s got %s", e.Detail, pe.Detail)
|
||||||
}
|
}
|
||||||
|
|
||||||
if pe.Code != e.Code {
|
if pe.Code != e.Code {
|
||||||
t.Fatal("Expected %s got %s", e.Code, pe.Code)
|
t.Fatalf("Expected %s got %s", e.Code, pe.Code)
|
||||||
}
|
}
|
||||||
|
|
||||||
if pe.Status != e.Status {
|
if pe.Status != e.Status {
|
||||||
t.Fatal("Expected %s got %s", e.Status, pe.Status)
|
t.Fatalf("Expected %s got %s", e.Status, pe.Status)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,6 @@ func (e *Example) PingPong(ctx context.Context, stream example.Example_PingPongS
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -55,5 +55,4 @@ func (e *Example) PingPong(ctx context.Context, stream server.Streamer) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ func TestEncodingEndpoints(t *testing.T) {
|
|||||||
|
|
||||||
// check there are two tags; old and new
|
// check there are two tags; old and new
|
||||||
if len(e) != 2 {
|
if len(e) != 2 {
|
||||||
t.Fatal("Expected 2 encoded tags, got %v", e)
|
t.Fatalf("Expected 2 encoded tags, got %v", e)
|
||||||
}
|
}
|
||||||
|
|
||||||
// check old encoding
|
// check old encoding
|
||||||
@ -72,7 +72,7 @@ func TestEncodingEndpoints(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !seen {
|
if !seen {
|
||||||
t.Fatal("Expected %s but not found", enc)
|
t.Fatalf("Expected %s but not found", enc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// decode
|
// decode
|
||||||
@ -133,29 +133,29 @@ func TestEncodingVersion(t *testing.T) {
|
|||||||
|
|
||||||
d, ok := decodeVersion(e)
|
d, ok := decodeVersion(e)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("Unexpected %t for %s", ok, data.encoded)
|
t.Fatalf("Unexpected %t for %s", ok, data.encoded)
|
||||||
}
|
}
|
||||||
|
|
||||||
if d != data.decoded {
|
if d != data.decoded {
|
||||||
t.Fatal("Expected %s got %s", data.decoded, d)
|
t.Fatalf("Expected %s got %s", data.decoded, d)
|
||||||
}
|
}
|
||||||
|
|
||||||
d, ok = decodeVersion([]string{data.encoded})
|
d, ok = decodeVersion([]string{data.encoded})
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("Unexpected %t for %s", ok, data.encoded)
|
t.Fatalf("Unexpected %t for %s", ok, data.encoded)
|
||||||
}
|
}
|
||||||
|
|
||||||
if d != data.decoded {
|
if d != data.decoded {
|
||||||
t.Fatal("Expected %s got %s", data.decoded, d)
|
t.Fatalf("Expected %s got %s", data.decoded, d)
|
||||||
}
|
}
|
||||||
|
|
||||||
d, ok = decodeVersion([]string{data.oldEncoded})
|
d, ok = decodeVersion([]string{data.oldEncoded})
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("Unexpected %t for %s", ok, data.oldEncoded)
|
t.Fatalf("Unexpected %t for %s", ok, data.oldEncoded)
|
||||||
}
|
}
|
||||||
|
|
||||||
if d != data.decoded {
|
if d != data.decoded {
|
||||||
t.Fatal("Expected %s got %s", data.decoded, d)
|
t.Fatalf("Expected %s got %s", data.decoded, d)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -293,7 +293,6 @@ func (s *service) call(ctx context.Context, server *server, sending *sync.Mutex,
|
|||||||
// no error, we send the special EOS error
|
// no error, we send the special EOS error
|
||||||
return lastStreamResponseError
|
return lastStreamResponseError
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := len(server.hdlrWrappers); i > 0; i-- {
|
for i := len(server.hdlrWrappers); i > 0; i-- {
|
||||||
|
@ -94,12 +94,12 @@ var (
|
|||||||
DefaultServer Server = newRpcServer()
|
DefaultServer Server = newRpcServer()
|
||||||
)
|
)
|
||||||
|
|
||||||
// Returns config options for the default service
|
// DefaultOptions returns config options for the default service
|
||||||
func DefaultOptions() Options {
|
func DefaultOptions() Options {
|
||||||
return DefaultServer.Options()
|
return DefaultServer.Options()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialises the default server with options passed in
|
// Init initialises the default server with options passed in
|
||||||
func Init(opt ...Option) {
|
func Init(opt ...Option) {
|
||||||
if DefaultServer == nil {
|
if DefaultServer == nil {
|
||||||
DefaultServer = newRpcServer(opt...)
|
DefaultServer = newRpcServer(opt...)
|
||||||
@ -107,18 +107,18 @@ func Init(opt ...Option) {
|
|||||||
DefaultServer.Init(opt...)
|
DefaultServer.Init(opt...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a new server with options passed in
|
// NewServer returns a new server with options passed in
|
||||||
func NewServer(opt ...Option) Server {
|
func NewServer(opt ...Option) Server {
|
||||||
return newRpcServer(opt...)
|
return newRpcServer(opt...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a new subscriber interface with the given topic
|
// NewSubscriber creates a new subscriber interface with the given topic
|
||||||
// and handler using the default server
|
// and handler using the default server
|
||||||
func NewSubscriber(topic string, h interface{}, opts ...SubscriberOption) Subscriber {
|
func NewSubscriber(topic string, h interface{}, opts ...SubscriberOption) Subscriber {
|
||||||
return DefaultServer.NewSubscriber(topic, h, opts...)
|
return DefaultServer.NewSubscriber(topic, h, opts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a new handler interface using the default server
|
// NewHandler creates a new handler interface using the default server
|
||||||
// Handlers are required to be a public object with public
|
// Handlers are required to be a public object with public
|
||||||
// methods. Call to a service method such as Foo.Bar expects
|
// methods. Call to a service method such as Foo.Bar expects
|
||||||
// the type:
|
// the type:
|
||||||
@ -132,29 +132,29 @@ func NewHandler(h interface{}, opts ...HandlerOption) Handler {
|
|||||||
return DefaultServer.NewHandler(h, opts...)
|
return DefaultServer.NewHandler(h, opts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Registers a handler interface with the default server to
|
// Handle registers a handler interface with the default server to
|
||||||
// handle inbound requests
|
// handle inbound requests
|
||||||
func Handle(h Handler) error {
|
func Handle(h Handler) error {
|
||||||
return DefaultServer.Handle(h)
|
return DefaultServer.Handle(h)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Registers a subscriber interface with the default server
|
// Subscribe registers a subscriber interface with the default server
|
||||||
// which subscribes to specified topic with the broker
|
// which subscribes to specified topic with the broker
|
||||||
func Subscribe(s Subscriber) error {
|
func Subscribe(s Subscriber) error {
|
||||||
return DefaultServer.Subscribe(s)
|
return DefaultServer.Subscribe(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Registers the default server with the discovery system
|
// Register registers the default server with the discovery system
|
||||||
func Register() error {
|
func Register() error {
|
||||||
return DefaultServer.Register()
|
return DefaultServer.Register()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deregisters the default server from the discovery system
|
// Deregister deregisters the default server from the discovery system
|
||||||
func Deregister() error {
|
func Deregister() error {
|
||||||
return DefaultServer.Deregister()
|
return DefaultServer.Deregister()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Blocking run starts the default server and waits for a kill
|
// Run starts the default server and waits for a kill
|
||||||
// signal before exiting. Also registers/deregisters the server
|
// signal before exiting. Also registers/deregisters the server
|
||||||
func Run() error {
|
func Run() error {
|
||||||
if err := Start(); err != nil {
|
if err := Start(); err != nil {
|
||||||
@ -176,19 +176,20 @@ func Run() error {
|
|||||||
return Stop()
|
return Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Starts the default server
|
// Start starts the default server
|
||||||
func Start() error {
|
func Start() error {
|
||||||
config := DefaultServer.Options()
|
config := DefaultServer.Options()
|
||||||
log.Printf("Starting server %s id %s", config.Name, config.Id)
|
log.Printf("Starting server %s id %s", config.Name, config.Id)
|
||||||
return DefaultServer.Start()
|
return DefaultServer.Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stops the default server
|
// Stop stops the default server
|
||||||
func Stop() error {
|
func Stop() error {
|
||||||
log.Printf("Stopping server")
|
log.Printf("Stopping server")
|
||||||
return DefaultServer.Stop()
|
return DefaultServer.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// String returns name of Server implementation
|
||||||
func String() string {
|
func String() string {
|
||||||
return DefaultServer.String()
|
return DefaultServer.String()
|
||||||
}
|
}
|
||||||
|
@ -122,8 +122,7 @@ func validateSubscriber(sub Subscriber) error {
|
|||||||
return fmt.Errorf("subscriber %v argument type not exported: %v", name, argType)
|
return fmt.Errorf("subscriber %v argument type not exported: %v", name, argType)
|
||||||
}
|
}
|
||||||
if typ.NumOut() != 1 {
|
if typ.NumOut() != 1 {
|
||||||
return fmt.Errorf(
|
return fmt.Errorf("subscriber %v has wrong number of outs: %v require signature %s",
|
||||||
"subscriber %v.%v has wrong number of outs: %v require signature %s",
|
|
||||||
name, typ.NumOut(), subSig)
|
name, typ.NumOut(), subSig)
|
||||||
}
|
}
|
||||||
if returnType := typ.Out(0); returnType != typeOfError {
|
if returnType := typ.Out(0); returnType != typeOfError {
|
||||||
|
@ -312,6 +312,7 @@ func (h *httpTransportListener) Close() error {
|
|||||||
|
|
||||||
func (h *httpTransportListener) Accept(fn func(Socket)) error {
|
func (h *httpTransportListener) Accept(fn func(Socket)) error {
|
||||||
var tempDelay time.Duration
|
var tempDelay time.Duration
|
||||||
|
|
||||||
for {
|
for {
|
||||||
c, err := h.listener.Accept()
|
c, err := h.listener.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -348,7 +349,6 @@ func (h *httpTransportListener) Accept(fn func(Socket)) error {
|
|||||||
fn(sock)
|
fn(sock)
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpTransport) Dial(addr string, opts ...DialOption) (Client, error) {
|
func (h *httpTransport) Dial(addr string, opts ...DialOption) (Client, error) {
|
||||||
@ -436,7 +436,7 @@ func (h *httpTransport) String() string {
|
|||||||
return "http"
|
return "http"
|
||||||
}
|
}
|
||||||
|
|
||||||
func newHttpTransport(opts ...Option) *httpTransport {
|
func newHTTPTransport(opts ...Option) *httpTransport {
|
||||||
var options Options
|
var options Options
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
o(&options)
|
o(&options)
|
||||||
|
@ -86,7 +86,6 @@ func (m *mockListener) Accept(fn func(transport.Socket)) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockTransport) Dial(addr string, opts ...transport.DialOption) (transport.Client, error) {
|
func (m *mockTransport) Dial(addr string, opts ...transport.DialOption) (transport.Client, error) {
|
||||||
|
@ -43,13 +43,13 @@ type DialOption func(*DialOptions)
|
|||||||
type ListenOption func(*ListenOptions)
|
type ListenOption func(*ListenOptions)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
DefaultTransport Transport = newHttpTransport()
|
DefaultTransport Transport = newHTTPTransport()
|
||||||
|
|
||||||
DefaultDialTimeout = time.Second * 5
|
DefaultDialTimeout = time.Second * 5
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewTransport(opts ...Option) Transport {
|
func NewTransport(opts ...Option) Transport {
|
||||||
return newHttpTransport(opts...)
|
return newHTTPTransport(opts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Dial(addr string, opts ...DialOption) (Client, error) {
|
func Dial(addr string, opts ...DialOption) (Client, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user