learned I didn't need git for external modules and different folders can have different mains
This commit is contained in:
		
							
								
								
									
										33
									
								
								pkg/gadget/program.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								pkg/gadget/program.go
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										31
									
								
								pkg/gadget/tape.go
									
									
									
									
									
										Normal 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")
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user