This repository has been archived on 2021-09-07. You can view files and clone it, but cannot push or open issues or pull requests.

38 lines
559 B
Go
Raw Normal View History

2018-01-17 16:31:15 +03:00
package proxy
import "errors"
type Human struct {
Gender string
Age int
}
type Bar interface {
Welcome(Human) error
}
type OpenBar struct {
Visitors []Human
}
func (b *OpenBar) Welcome(h Human) error {
b.Visitors = append(b.Visitors, h)
return nil
}
type BarProxy struct {
2020-09-07 10:30:22 -04:00
Bar
2018-01-17 16:31:15 +03:00
}
func (b *BarProxy) Welcome(h Human) error {
if h.Gender == "female" && h.Age < 20 {
return errors.New("Females under 20 not allowed.")
}
if h.Gender == "male" && h.Age < 18 {
return errors.New("Males under 18 not allowed.")
}
2020-09-07 10:30:22 -04:00
return b.Bar.Welcome(h)
2018-01-17 16:31:15 +03:00
}