-
Notifications
You must be signed in to change notification settings - Fork 22
/
main.go
42 lines (30 loc) · 801 Bytes
/
main.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
package main
import "fmt"
type Client interface {
Request(string) string
}
type AuthClient struct {
key string
}
func (c AuthClient) Request(url string) string {
return fmt.Sprintf("response for %s with %s", url, c.key)
}
type NoAuthClient struct {
}
func (c NoAuthClient) Request(url string) string {
return fmt.Sprintf("response for %s", url)
}
type Requester struct {
client Client
}
func (r Requester) Request(url string) string {
return r.client.Request(url)
}
func main() {
authClient := AuthClient{"secure_key"}
noAuthClient := NoAuthClient{}
authRequester := Requester{authClient}
noAuthRequester := Requester{noAuthClient}
fmt.Printf("authRequest -> %s\n", authRequester.Request("localhost"))
fmt.Printf("noAuthRequest -> %s\n", noAuthRequester.Request("localhost"))
}