Skip to content

Commit

Permalink
api: make New to receive Container as a required param
Browse files Browse the repository at this point in the history
* drop support for receving Options as params since there is no need anymore.
  • Loading branch information
ilgooz committed Apr 11, 2019
1 parent 5552a57 commit 92b5f3a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 30 deletions.
27 changes: 5 additions & 22 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,12 @@ type API struct {
container container.Container
}

// Option is a configuration func for MESG.
type Option func(*API)

// New creates a new API with given options.
func New(db database.ServiceDB, execDB database.ExecutionDB, options ...Option) (*API, error) {
a := &API{db: db, execDB: execDB}
for _, option := range options {
option(a)
}
if a.container == nil {
var err error
a.container, err = container.New()
if err != nil {
return nil, err
}
}
return a, nil
}

// ContainerOption configures underlying container access API.
func ContainerOption(container container.Container) Option {
return func(a *API) {
a.container = container
func New(c container.Container, db database.ServiceDB, execDB database.ExecutionDB) *API {
return &API{
container: c,
db: db,
execDB: execDB,
}
}

Expand Down
3 changes: 1 addition & 2 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ func newTesting(t *testing.T) (*API, *apiTesting) {
execDB, err := database.NewExecutionDB(execdbname)
require.NoError(t, err)

a, err := New(db, execDB, ContainerOption(containerMock))
require.NoError(t, err)
a := New(containerMock, db, execDB)

return a, &apiTesting{
T: t,
Expand Down
5 changes: 1 addition & 4 deletions core/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ func initDependencies() (*dependencies, error) {
}

// init api.
api, err := api.New(serviceDB, executionDB, api.ContainerOption(c))
if err != nil {
return nil, err
}
api := api.New(c, serviceDB, executionDB)

return &dependencies{
config: config,
Expand Down
3 changes: 1 addition & 2 deletions interface/grpc/core/test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ func newServerWithContainer(t *testing.T, c container.Container) (*Server, func(
execDB, err := database.NewExecutionDB(execdbname)
require.NoError(t, err)

a, err := api.New(db, execDB, api.ContainerOption(c))
require.NoError(t, err)
a := api.New(c, db, execDB)

server := NewServer(a)

Expand Down

0 comments on commit 92b5f3a

Please sign in to comment.