Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/gonitro/nitro
Browse files Browse the repository at this point in the history
  • Loading branch information
crazybber committed Nov 26, 2020
2 parents 500df15 + aa8be60 commit d154a26
Show file tree
Hide file tree
Showing 46 changed files with 359 additions and 359 deletions.
2 changes: 1 addition & 1 deletion app/client/backoff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (r *testRequest) ContentType() string {
return r.contentType
}

func (r *testRequest) Service() string {
func (r *testRequest) App() string {
return r.service
}

Expand Down
2 changes: 1 addition & 1 deletion app/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Message interface {
// Request is the interface for a synchronous request used by Call or Stream
type Request interface {
// The service to call
Service() string
App() string
// The action to take
Method() string
// The endpoint to invoke
Expand Down
6 changes: 3 additions & 3 deletions app/client/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ func LookupRoute(ctx context.Context, req Request, opts CallOptions) ([]string,
}

// lookup the routes which can be used to execute the request
routes, err := opts.Router.Lookup(req.Service(), query...)
routes, err := opts.Router.Lookup(req.App(), query...)
if err == router.ErrRouteNotFound {
return nil, errors.InternalServerError("nitro", "service %s: %s", req.Service(), err.Error())
return nil, errors.InternalServerError("nitro", "service %s: %s", req.App(), err.Error())
} else if err != nil {
return nil, errors.InternalServerError("nitro", "error getting next %s node: %s", req.Service(), err.Error())
return nil, errors.InternalServerError("nitro", "error getting next %s node: %s", req.App(), err.Error())
}

// sort by lowest metric first
Expand Down
8 changes: 4 additions & 4 deletions app/client/rpc/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (

var (
// mock data
testData = map[string][]*registry.Service{
testData = map[string][]*registry.App{
"foo": {
{
Name: "foo",
Version: "1.0.0",
Nodes: []*registry.Node{
Instances: []*registry.Instance{
{
Id: "foo-1.0.0-123",
Address: "localhost:9999",
Expand All @@ -31,7 +31,7 @@ var (
{
Name: "foo",
Version: "1.0.1",
Nodes: []*registry.Node{
Instances: []*registry.Instance{
{
Id: "foo-1.0.1-321",
Address: "localhost:6666",
Expand All @@ -44,7 +44,7 @@ var (
{
Name: "foo",
Version: "1.0.3",
Nodes: []*registry.Node{
Instances: []*registry.Instance{
{
Id: "foo-1.0.3-345",
Address: "localhost:8888",
Expand Down
4 changes: 2 additions & 2 deletions app/client/rpc/rpc_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func setHeaders(m *codec.Message, stream string) {
}

set("Id", m.Id)
set("Service", m.Target)
set("App", m.Target)
set("Method", m.Method)
set("Endpoint", m.Endpoint)
set("Error", m.Error)
Expand All @@ -117,7 +117,7 @@ func setHeaders(m *codec.Message, stream string) {
}

// setupProtocol sets up the old protocol
func setupProtocol(msg *network.Message, node *registry.Node) codec.NewCodec {
func setupProtocol(msg *network.Message, node *registry.Instance) codec.NewCodec {
// get the protocol from node metadata
if protocol := node.Metadata["protocol"]; len(protocol) > 0 {
return nil
Expand Down
2 changes: 1 addition & 1 deletion app/client/rpc/rpc_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (r *rpcRequest) ContentType() string {
return r.contentType
}

func (r *rpcRequest) Service() string {
func (r *rpcRequest) App() string {
return r.service
}

Expand Down
4 changes: 2 additions & 2 deletions app/client/rpc/rpc_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (

func TestRequestOptions(t *testing.T) {
r := newRequest("service", "endpoint", nil, "application/json")
if r.Service() != "service" {
t.Fatalf("expected 'service' got %s", r.Service())
if r.App() != "service" {
t.Fatalf("expected 'service' got %s", r.App())
}
if r.Endpoint() != "endpoint" {
t.Fatalf("expected 'endpoint' got %s", r.Endpoint())
Expand Down
4 changes: 2 additions & 2 deletions app/client/rpc/rpc_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (r *rpcStream) Send(msg interface{}) error {

req := codec.Message{
Id: r.id,
Target: r.request.Service(),
Target: r.request.App(),
Method: r.request.Method(),
Endpoint: r.request.Endpoint(),
Type: codec.Request,
Expand Down Expand Up @@ -146,7 +146,7 @@ func (r *rpcStream) Close() error {
// no need to check for error
r.codec.Write(&codec.Message{
Id: r.id,
Target: r.request.Service(),
Target: r.request.App(),
Method: r.request.Method(),
Endpoint: r.request.Endpoint(),
Type: codec.Error,
Expand Down
14 changes: 7 additions & 7 deletions app/client/rpc/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

func newTestRouter() router.Router {
reg := memory.NewRegistry(memory.Services(testData))
reg := memory.NewRegistry(memory.Apps(testData))
return regRouter.NewRouter(router.Registry(reg))
}

Expand All @@ -28,8 +28,8 @@ func TestCallAddress(t *testing.T) {
return func(ctx context.Context, node string, req client.Request, rsp interface{}, opts client.CallOptions) error {
called = true

if req.Service() != service {
return fmt.Errorf("expected service: %s got %s", service, req.Service())
if req.App() != service {
return fmt.Errorf("expected service: %s got %s", service, req.App())
}

if req.Endpoint() != endpoint {
Expand Down Expand Up @@ -114,8 +114,8 @@ func TestCallWrapper(t *testing.T) {
return func(ctx context.Context, node string, req client.Request, rsp interface{}, opts client.CallOptions) error {
called = true

if req.Service() != service {
return fmt.Errorf("expected service: %s got %s", service, req.Service())
if req.App() != service {
return fmt.Errorf("expected service: %s got %s", service, req.App())
}

if req.Endpoint() != endpoint {
Expand All @@ -137,10 +137,10 @@ func TestCallWrapper(t *testing.T) {
client.WrapCall(wrap),
)

r.Options().Registry.Register(&registry.Service{
r.Options().Registry.Add(&registry.App{
Name: service,
Version: "latest",
Nodes: []*registry.Node{
Instances: []*registry.Instance{
{
Id: id,
Address: address,
Expand Down
2 changes: 1 addition & 1 deletion app/crypto/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ type Resource struct {
Name string `json:"name"`
// Type of resource, e.g. service
Type string `json:"type"`
// Endpoint resource e.g NotesService.Create
// Endpoint resource e.g NotesApp.Create
Endpoint string `json:"endpoint"`
}

Expand Down
4 changes: 2 additions & 2 deletions app/crypto/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestVerify(t *testing.T) {
Error: ErrForbidden,
},
{
Name: "CatchallServiceRuleMatch",
Name: "CatchallAppRuleMatch",
Resource: srvResource,
Account: &Account{},
Rules: []*Rule{
Expand All @@ -96,7 +96,7 @@ func TestVerify(t *testing.T) {
},
},
{
Name: "CatchallServiceRuleNoMatch",
Name: "CatchallAppRuleNoMatch",
Resource: srvResource,
Account: &Account{},
Rules: []*Rule{
Expand Down
4 changes: 2 additions & 2 deletions app/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ func BadGateway(id, format string, a ...interface{}) error {
}
}

// ServiceUnavailable generates a 503 error
func ServiceUnavailable(id, format string, a ...interface{}) error {
// AppUnavailable generates a 503 error
func AppUnavailable(id, format string, a ...interface{}) error {
return &Error{
Id: id,
Code: 503,
Expand Down
12 changes: 6 additions & 6 deletions app/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,17 @@ func Metadata(md map[string]string) Option {
}
}

// RegisterTTL specifies the TTL to use when registering the app
func RegisterTTL(t time.Duration) Option {
// AddTTL specifies the TTL to use when registering the app
func AddTTL(t time.Duration) Option {
return func(o *Options) {
o.Server.Init(server.RegisterTTL(t))
o.Server.Init(server.AddTTL(t))
}
}

// RegisterInterval specifies the interval on which to re-register
func RegisterInterval(t time.Duration) Option {
// AddInterval specifies the interval on which to re-register
func AddInterval(t time.Duration) Option {
return func(o *Options) {
o.Server.Init(server.RegisterInterval(t))
o.Server.Init(server.AddInterval(t))
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (s *nitroProgram) Name(name string) {
)
}

// Init initialises options. Additionally it calls cmd.Init
// Init initialises options. Registeritionally it calls cmd.Init
// which parses command line flags. cmd.Init is only called
// on first Init.
func (s *nitroProgram) Init(opts ...Option) {
Expand Down
Loading

0 comments on commit d154a26

Please sign in to comment.