-
Notifications
You must be signed in to change notification settings - Fork 2
/
kcd.go
54 lines (42 loc) · 1.29 KB
/
kcd.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
package kcd
import (
"github.com/alexisvisco/kcd/pkg/extractor"
"github.com/alexisvisco/kcd/pkg/hook"
)
// Configuration is the main configuration type of kcd.
type Configuration struct {
StringsExtractors []extractor.Strings
ValueExtractors []extractor.Value
ErrorHook hook.ErrorHook
BindHook hook.BindHook
ValidateHook hook.ValidateHook
RenderHook hook.RenderHook
LogHook hook.LogHook
Verbose bool
}
// Config is the instance of Configuration type.
// You can add as many extractor you want, modify them ...
// You can set your custom hook too.
var Config = Configuration{
StringsExtractors: []extractor.Strings{extractor.Path{}, extractor.Header{}, extractor.Query{}},
ValueExtractors: []extractor.Value{extractor.Context{}},
ErrorHook: hook.Error,
RenderHook: hook.Render,
BindHook: hook.Bind(256 * 1024),
ValidateHook: hook.Validate,
LogHook: hook.Log,
}
func (c Configuration) stringsTags() []string {
tags := make([]string, 0, len(c.StringsExtractors))
for _, se := range c.StringsExtractors {
tags = append(tags, se.Tag())
}
return tags
}
func (c Configuration) valuesTags() []string {
tags := make([]string, 0, len(c.ValueExtractors)+1)
for _, ve := range c.ValueExtractors {
tags = append(tags, ve.Tag())
}
return append(tags, "default")
}