request.go 667 Bytes
Newer Older
Matt Bell's avatar
Matt Bell committed
1 2 3 4 5
package commands

// Request represents a call to a command from a consumer
type Request struct {
  options map[string]interface{}
6
  arguments []string
Matt Bell's avatar
Matt Bell committed
7 8
}

9 10
func (r *Request) Option(name string) interface{} {
  return r.options[name]
Matt Bell's avatar
Matt Bell committed
11 12
}

13 14 15 16 17 18 19 20
func (r *Request) SetOption(option Option, value interface{}) {
  // saves the option value in the map, indexed by each name
  // (so commands can retrieve it using any of the names)
  for _, name := range option.Names {
    r.options[name] = value
  }
}

21 22 23
func (r *Request) Arguments() []string {
  return r.arguments
}
Matt Bell's avatar
Matt Bell committed
24 25 26 27

func NewRequest() *Request {
  return &Request{
    make(map[string]interface{}),
28
    make([]string, 0),
Matt Bell's avatar
Matt Bell committed
29 30
  }
}