Created
March 1, 2016 17:56
-
-
Save EwanValentine/4ee3b97c2505a267423e to your computer and use it in GitHub Desktop.
Container test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
type Container map[string]interface{} | |
func (container Container) Add(name string, object interface{}) Container { | |
container[name] = object | |
return container | |
} | |
func (container Container) Remove(name string) Container { | |
delete(container, name) | |
return container | |
} | |
func main() { | |
container := make(Container) | |
container.Add("tst", "testing123") | |
container.Remove("test") | |
myApp := &MyApp{} | |
container["my.service"] = myApp | |
fmt.Println(container["my.service"].(*MyApp).TestService(23)) | |
fmt.Println(container["tst"].(string)) | |
} | |
type MyApp struct {} | |
func (myApp *MyApp) MyService() string { | |
return "testing 123" | |
} | |
func (myApp *MyApp) TestService(param int) int { | |
return 12 + param | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment