| 32 | } |
| 33 | |
| 34 | func main() { |
| 35 | |
| 36 | // Create a slice of publisher interface values. Assign |
| 37 | // the address of a pubsub.PubSub value and the address of |
| 38 | // a mock value. |
| 39 | pubs := []publisher{ |
| 40 | pubsub.New("localhost"), |
| 41 | &mock{}, |
| 42 | } |
| 43 | |
| 44 | // Range over the interface value to see how the publisher |
| 45 | // interface provides the level of decoupling the user needs. |
| 46 | // The pubsub package did not need to provide the interface type. |
| 47 | for _, p := range pubs { |
| 48 | p.Publish("key", "value") |
| 49 | p.Subscribe("key") |
| 50 | } |
| 51 | } |