-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathiris_context_provider.go
More file actions
45 lines (38 loc) · 939 Bytes
/
iris_context_provider.go
File metadata and controls
45 lines (38 loc) · 939 Bytes
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
package transform
import (
"strings"
"github.com/kataras/iris"
)
type IrisContextProvider struct {
context iris.Context
}
func NewIrisContextProvider(v interface{}) *IrisContextProvider {
if ctx, ok := v.(iris.Context); ok {
return &IrisContextProvider{
context: ctx,
}
}
panic(ErrTypeNotMatch)
}
func (this *IrisContextProvider) Set(f string, v interface{}) error {
return nil
}
func (this *IrisContextProvider) Get(f string) (interface{}, error) {
fs := strings.SplitN(f, ".", 2)
if len(fs) != 2 {
panic(ErrFieldNotFound)
}
if fs[0] == "query" {
return this.context.URLParam(fs[1]), nil
} else if fs[0] == "post" {
return this.context.PostValue(fs[1]), nil
} else if fs[0] == "params" {
return this.context.Params().Get(fs[1]), nil
} else if fs[0] == "cookie" {
return this.context.GetCookie(fs[1]), nil
}
return "", nil
}
func (this *IrisContextProvider) Fields() []string {
return []string{}
}