forked from shomali11/slacker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
request.go
60 lines (49 loc) · 1.94 KB
/
request.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package slacker
import (
"github.com/shomali11/proper"
)
const (
empty = ""
)
// NewRequest creates a new Request structure
func NewRequest(botCtx BotContext, properties *proper.Properties) Request {
return &request{botCtx: botCtx, properties: properties}
}
// Request interface that contains the Event received and parameters
type Request interface {
Param(key string) string
StringParam(key string, defaultValue string) string
BooleanParam(key string, defaultValue bool) bool
IntegerParam(key string, defaultValue int) int
FloatParam(key string, defaultValue float64) float64
Properties() *proper.Properties
}
// request contains the Event received and parameters
type request struct {
botCtx BotContext
properties *proper.Properties
}
// Param attempts to look up a string value by key. If not found, return the an empty string
func (r *request) Param(key string) string {
return r.StringParam(key, empty)
}
// StringParam attempts to look up a string value by key. If not found, return the default string value
func (r *request) StringParam(key string, defaultValue string) string {
return r.properties.StringParam(key, defaultValue)
}
// BooleanParam attempts to look up a boolean value by key. If not found, return the default boolean value
func (r *request) BooleanParam(key string, defaultValue bool) bool {
return r.properties.BooleanParam(key, defaultValue)
}
// IntegerParam attempts to look up a integer value by key. If not found, return the default integer value
func (r *request) IntegerParam(key string, defaultValue int) int {
return r.properties.IntegerParam(key, defaultValue)
}
// FloatParam attempts to look up a float value by key. If not found, return the default float value
func (r *request) FloatParam(key string, defaultValue float64) float64 {
return r.properties.FloatParam(key, defaultValue)
}
// Properties returns the properties of the request
func (r *request) Properties() *proper.Properties {
return r.properties
}