learned I didn't need git for external modules and different folders can have different mains

This commit is contained in:
2024-02-03 11:00:34 -05:00
parent 943191e9dd
commit 19b1581f10
37 changed files with 439 additions and 16 deletions

33
pkg/gadget/program.go Normal file
View File

@ -0,0 +1,33 @@
package main
type Player interface {
Play(string)
Stop()
}
func TryOut(player Player) {
player.Play("Test Track")
player.Stop()
recorder, ok := player.(TapeRecorder)
if ok {
recorder.Record()
}
}
func playList(device Player, songs []string) {
for _, song := range songs {
device.Play(song)
}
device.Stop()
}
func main() {
mixTape := []string{"Jessie's Girl", "Whip It", "9 to 5"}
var player Player = TapePlayer{}
playList(player, mixTape)
player = TapeRecorder{}
playList(player, mixTape)
TryOut(TapeRecorder{})
TryOut(TapePlayer{})
}

31
pkg/gadget/tape.go Normal file
View File

@ -0,0 +1,31 @@
package main
import "fmt"
type TapePlayer struct {
Batteries string
}
func (t TapePlayer) Play(song string) {
fmt.Println("Playing", song)
}
func (t TapePlayer) Stop() {
fmt.Println("Stopped")
}
type TapeRecorder struct {
Microphone int
}
func (t TapeRecorder) Play(song string) {
fmt.Println("Playing", song)
}
func (t TapeRecorder) Record() {
fmt.Println("Recording")
}
func (t TapeRecorder) Stop() {
fmt.Println("Stopped")
}