Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bufdev committed Mar 3, 2017
1 parent e58d1fe commit 018b001
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 48 deletions.
16 changes: 3 additions & 13 deletions modules/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,9 @@ func globalBackendStatsClient() *statsClient {

// New creates an async task queue ModuleProvider.
func New(createFunc BackendCreateFunc) service.ModuleProvider {
return &moduleProvider{createFunc}
}

type moduleProvider struct {
createFunc BackendCreateFunc
}

func (p *moduleProvider) Name() string {
return "task"
}

func (p *moduleProvider) Create(host service.Host) (service.Module, error) {
return newAsyncModuleSingleton(host, p.createFunc)
return service.ModuleProviderFromFunc("task", func(host service.Host) (service.Module, error) {
return newAsyncModuleSingleton(host, createFunc)
})
}

func newAsyncModuleSingleton(
Expand Down
17 changes: 3 additions & 14 deletions modules/uhttp/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,9 @@ type GetHandlersFunc func(service service.Host) []RouteHandler

// New returns a new HTTP ModuleProvider.
func New(hookup GetHandlersFunc, options ...ModuleOption) service.ModuleProvider {
return &moduleProvider{hookup, options}
}

type moduleProvider struct {
hookup GetHandlersFunc
options []ModuleOption
}

func (p *moduleProvider) Name() string {
return "http"
}

func (p *moduleProvider) Create(host service.Host) (service.Module, error) {
return newModule(host, p.hookup, p.options...)
return service.ModuleProviderFromFunc("http", func(host service.Host) (service.Module, error) {
return newModule(host, hookup, options...)
})
}

func newModule(
Expand Down
17 changes: 3 additions & 14 deletions modules/yarpc/yarpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,9 @@ type ServiceCreateFunc func(svc service.Host) ([]transport.Procedure, error)

// New creates a YARPC Module from a service func
func New(hookup ServiceCreateFunc, options ...ModuleOption) service.ModuleProvider {
return &moduleProvider{hookup, options}
}

type moduleProvider struct {
hookup ServiceCreateFunc
options []ModuleOption
}

func (p *moduleProvider) Name() string {
return "yarpc"
}

func (p *moduleProvider) Create(host service.Host) (service.Module, error) {
return newYARPCModule(host, p.hookup, p.options...)
return service.ModuleProviderFromFunc("yarpc", func(host service.Host) (service.Module, error) {
return newYARPCModule(host, hookup, options...)
})
}

// Module is an implementation of a core RPC module using YARPC.
Expand Down
10 changes: 5 additions & 5 deletions service/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ import (

// ModuleProvider provides Modules.
type ModuleProvider interface {
// Name is the name that will be used for a new Module
// DefaultName is the name that will be used for a new Module
// if no name is given as a ModuleOption.
Name() string
DefaultName() string
// Create a new Module. The name of the Host and the scoping
// of associated functions on the Host will be done using a name
// provided by a ModuleOption, or by the Name on this ModuleProvider.
// provided by a ModuleOption, or by the DefaultName on this ModuleProvider.
Create(Host) (Module, error)
}

Expand All @@ -56,7 +56,7 @@ type moduleProviderFunc struct {
createFunc func(Host) (Module, error)
}

func (m *moduleProviderFunc) Name() string { return m.name }
func (m *moduleProviderFunc) DefaultName() string { return m.name }
func (m *moduleProviderFunc) Create(host Host) (Module, error) { return m.createFunc(host) }

// ModuleOption is a function that configures module creation.
Expand Down Expand Up @@ -120,7 +120,7 @@ func newModuleWrapper(
}
}
if moduleOptions.name == "" {
moduleOptions.name = moduleProvider.Name()
moduleOptions.name = moduleProvider.DefaultName()
}
scopedHost, err := newScopedHost(
host,
Expand Down
4 changes: 2 additions & 2 deletions service/stub_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func NewStubModuleProvider(name string, stubModule *StubModule) *StubModuleProvi
return &StubModuleProvider{name, NewStubModuleCreateFunc(stubModule)}
}

// Name returns the name.
func (p *StubModuleProvider) Name() string {
// DefaultName returns the default name.
func (p *StubModuleProvider) DefaultName() string {
return p.NameVal
}

Expand Down

0 comments on commit 018b001

Please sign in to comment.