diff --git a/interfaces/go.mod b/interfaces/go.mod new file mode 100644 index 0000000..f9ed850 --- /dev/null +++ b/interfaces/go.mod @@ -0,0 +1,3 @@ +module lovelynet.net/interfaces + +go 1.17 diff --git a/interfaces/main.go b/interfaces/main.go new file mode 100644 index 0000000..558025d --- /dev/null +++ b/interfaces/main.go @@ -0,0 +1,32 @@ +package main + +import "fmt" + +type bot interface { + getGreeting() string +} + +type englishBot struct{} +type spanishBot struct{} + +func main() { + eb := englishBot{} + sb := spanishBot{} + + printGreetings(eb) + printGreetings(sb) +} + +func printGreetings(b bot) { + fmt.Println(b.getGreeting()) +} + +func (englishBot) getGreeting() string { + // Very custom logic + return "Hello" +} + +func (spanishBot) getGreeting() string { + // Very custom logic + return "Hola!" +} diff --git a/maps/go.mod b/maps/go.mod new file mode 100644 index 0000000..c99e177 --- /dev/null +++ b/maps/go.mod @@ -0,0 +1,3 @@ +module lovelynet.net/maps + +go 1.17 diff --git a/maps/main.go b/maps/main.go new file mode 100644 index 0000000..e96c0dd --- /dev/null +++ b/maps/main.go @@ -0,0 +1,19 @@ +package main + +import "fmt" + +func main() { + colours := map[string]string{ + "red": "#ff0000", + "green": "#4bf745", + "white": "#ffffff", + } + + printMap(colours) +} + +func printMap(c map[string]string) { + for colour, hex := range c { + fmt.Println(colour, hex) + } +}