-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
operation.go
33 lines (28 loc) · 827 Bytes
/
operation.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
package golax
import "strings"
// Operation is a terminal node, ready to execute code but exposed as Google
// custom methods (with :operation syntax)
type Operation struct {
Path string // Operation name
Interceptors []*Interceptor
Methods map[string]Handler
}
// NewOperation instances and initialize an Operation
func NewOperation() *Operation {
return &Operation{
Path: "",
Interceptors: []*Interceptor{},
Methods: map[string]Handler{},
}
}
// Method implement an HTTP method for an operation
func (o *Operation) Method(m string, h Handler) *Operation {
M := strings.ToUpper(m)
o.Methods[M] = h
return o
}
// Interceptor attaches an Interceptor to an operation
func (o *Operation) Interceptor(m *Interceptor) *Operation {
o.Interceptors = append(o.Interceptors, m)
return o
}