-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutils.go
49 lines (41 loc) · 971 Bytes
/
utils.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
// Copyright 2017 King Qiu. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
// https://github.com/qjw/kelly
package kelly
import (
"encoding/json"
"github.com/qjw/kelly/binding"
"github.com/urfave/negroni"
"io/ioutil"
"net/http"
)
func wrapHandlerFunc(f HandlerFunc) negroni.HandlerFunc {
return func(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
f(newContext(rw, r, next))
}
}
func filterFlags(content string) string {
for i, char := range content {
if char == ' ' || char == ';' {
return content[:i]
}
}
return content
}
func JsonConfToStruct(path string, obj interface{}) error {
file, err := ioutil.ReadFile(path)
if err != nil {
return err
}
if err := json.Unmarshal(file, obj); err != nil {
return err
}
return nil
}
func Validate(obj interface{}) error {
return binding.Validate(obj)
}
func Version() string {
return version
}