package airport import ( "fmt" "time" ) var prohibitedItems = map[string]bool{"Knife": true, "Gun": true, "Explosives": true} type SecurityCheck struct { processingTime time.Duration //TODO: extend } func NewSecurityCheck(processingTime time.Duration) SecurityCheck { return SecurityCheck{ processingTime: processingTime, } } // processes one passenger at a time. Each passenger must at least spend the processingTime at the security check func (sc *SecurityCheck) Start() { } // returns an error if // - the passenger has no boarding pass // - the passenger's boardings pass does not match the name // - the passenger carries a prohibited item func (sc SecurityCheck) Process(p Passenger) error { time.Sleep(sc.processingTime) if p.BoardingPass == nil { return fmt.Errorf("%v has no boarding pass!", p.Name) } if p.BoardingPass.Name != p.Name { return fmt.Errorf("Name on boaring pass (%v) doesn't match with passengers name (%v)!", p.BoardingPass.Name, p.Name) } for bagNr, bag := range p.Bags { for _, item := range bag.Items { if prohibitedItems[item] { return fmt.Errorf("Found %v in bag %v which is a prohibited item!", item, bagNr) } } } for _, item := range p.CarryOnItems { if prohibitedItems[item] { return fmt.Errorf("Found %v on %v which is a prohibited item!", item, p.Name) } } return nil }