Skip to content

Instantly share code, notes, and snippets.

@EwanValentine
Created March 1, 2016 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EwanValentine/4ee3b97c2505a267423e to your computer and use it in GitHub Desktop.
Save EwanValentine/4ee3b97c2505a267423e to your computer and use it in GitHub Desktop.
Container test
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