forked from ardanlabs/gotraining
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template1.go
51 lines (38 loc) · 1.54 KB
/
template1.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// All material is licensed under the Apache License Version 2.0, January 2004
// http://www.apache.org/licenses/LICENSE-2.0
// https://play.golang.org/p/QoRYJOHiZS
// Copy the code from the template. Declare a new type called hockey
// which embeds the sports type. Implement the matcher interface for hockey.
// When implementing the match method for hockey, call into the match method
// for the embedded sport type to check the embedded fields first. Then create
// two hockey values inside the slice of matchers and perform the search.
package main
import "strings"
// matcher defines the behavior required for performing matching.
type matcher interface {
match(searchTerm string) bool
}
// sport represents a sports team.
type sport struct {
team string
city string
}
// match checks the value for the specified term.
func (s sport) match(searchTerm string) bool {
return strings.Contains(s.team, searchTerm) || strings.Contains(s.city, searchTerm)
}
// Declare a struct type named hockey that represents specific
// hockey information. Have it embed the sport type first.
// match checks the value for the specified term.
func ( /* receiver type */ ) match(searchTerm string) bool {
// Make sure you call into match method for the embedded sport type.
// Implement the search for the new fields.
return false
}
// main is the entry point for the application.
func main() {
// Define the term to match.
// Create a slice of matcher values to match.
// Display what we are trying to match.
// Range of each matcher value and check the term.
}