Gin: add gin into the framework
This commit is contained in:
@ -18,16 +18,14 @@ type Container interface {
|
||||
// IsBound returns true the provider is bound to the container.
|
||||
IsBound(name string) bool
|
||||
|
||||
// Get gets or creates a service by its name.
|
||||
// Make gets or creates a service by its name.
|
||||
//
|
||||
// Return error if the service cannot be initiated or doesn't exist.
|
||||
Get(name string) (interface{}, error)
|
||||
Make(name string) (interface{}, error)
|
||||
|
||||
// JustGet gets a service, return nil if error.
|
||||
JustGet(name string) interface{}
|
||||
|
||||
// GetExisted gets an initiated service by its name.
|
||||
GetExisted(name string) interface{}
|
||||
// MustMake makes a service, supposing that it is not instantiated before.
|
||||
// Return nil if error.
|
||||
MustMake(name string) interface{}
|
||||
|
||||
// MakeNew creates a new instance of the service with different parameters.
|
||||
//
|
||||
@ -109,15 +107,11 @@ func (c *GoWebContainer) getServiceProvider(name string) ServiceProvider {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *GoWebContainer) Get(name string) (interface{}, error) {
|
||||
func (c *GoWebContainer) Make(name string) (interface{}, error) {
|
||||
return c.makeServiceInstance(name, nil, false)
|
||||
}
|
||||
|
||||
func (c *GoWebContainer) GetExisted(name string) interface{} {
|
||||
return c.getServiceInstance(name)
|
||||
}
|
||||
|
||||
func (c *GoWebContainer) JustGet(name string) interface{} {
|
||||
func (c *GoWebContainer) MustMake(name string) interface{} {
|
||||
ins, err := c.makeServiceInstance(name, nil, false)
|
||||
if err != nil {
|
||||
return nil
|
||||
|
@ -75,7 +75,7 @@ func TestBind(t *testing.T) {
|
||||
|
||||
container.Bind(provider)
|
||||
|
||||
dummyService := container.JustGet(DummyProviderName).(IDummyService)
|
||||
dummyService := container.MustMake(DummyProviderName).(IDummyService)
|
||||
|
||||
want := DummyStruct{
|
||||
Name: "Dummy!",
|
||||
|
1
framework/gin
Submodule
1
framework/gin
Submodule
Submodule framework/gin added at f05f966a08
Reference in New Issue
Block a user