Browse Source

rename Error to Fail

Paul 6 years ago
parent
commit
33c6c7939e
2 changed files with 9 additions and 104 deletions
  1. 1
    100
      Gopkg.lock
  2. 8
    4
      request/request.go

+ 1
- 100
Gopkg.lock View File

@@ -1,18 +1,6 @@
1 1
 # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
2 2
 
3 3
 
4
-[[projects]]
5
-  branch = "master"
6
-  name = "github.com/Unknwon/i18n"
7
-  packages = ["."]
8
-  revision = "b64d336589669d317928070e70ba0ae558f16633"
9
-
10
-[[projects]]
11
-  name = "github.com/fsnotify/fsnotify"
12
-  packages = ["."]
13
-  revision = "c2828203cd70a50dcccfb2761f8b1f8ceef9a8e9"
14
-  version = "v1.4.7"
15
-
16 4
 [[projects]]
17 5
   branch = "master"
18 6
   name = "github.com/gin-contrib/sse"
@@ -36,47 +24,18 @@
36 24
   revision = "925541529c1fa6821df4e44ce2723319eb2be768"
37 25
   version = "v1.0.0"
38 26
 
39
-[[projects]]
40
-  branch = "master"
41
-  name = "github.com/hashicorp/hcl"
42
-  packages = [
43
-    ".",
44
-    "hcl/ast",
45
-    "hcl/parser",
46
-    "hcl/printer",
47
-    "hcl/scanner",
48
-    "hcl/strconv",
49
-    "hcl/token",
50
-    "json/parser",
51
-    "json/scanner",
52
-    "json/token"
53
-  ]
54
-  revision = "ef8a98b0bbce4a65b5aa4c368430a80ddc533168"
55
-
56 27
 [[projects]]
57 28
   name = "github.com/json-iterator/go"
58 29
   packages = ["."]
59 30
   revision = "ca39e5af3ece67bbcda3d0f4f56a8e24d9f2dad4"
60 31
   version = "1.1.3"
61 32
 
62
-[[projects]]
63
-  name = "github.com/magiconair/properties"
64
-  packages = ["."]
65
-  revision = "c3beff4c2358b44d0493c7dda585e7db7ff28ae6"
66
-  version = "v1.7.6"
67
-
68 33
 [[projects]]
69 34
   name = "github.com/mattn/go-isatty"
70 35
   packages = ["."]
71 36
   revision = "0360b2af4f38e8d38c7fce2a9f4e702702d73a39"
72 37
   version = "v0.0.3"
73 38
 
74
-[[projects]]
75
-  branch = "master"
76
-  name = "github.com/mitchellh/mapstructure"
77
-  packages = ["."]
78
-  revision = "00c29f56e2386353d58c599509e8dc3801b0d716"
79
-
80 39
 [[projects]]
81 40
   name = "github.com/modern-go/concurrent"
82 41
   packages = ["."]
@@ -89,51 +48,12 @@
89 48
   revision = "1df9eeb2bb81f327b96228865c5687bc2194af3f"
90 49
   version = "1.0.0"
91 50
 
92
-[[projects]]
93
-  name = "github.com/pelletier/go-toml"
94
-  packages = ["."]
95
-  revision = "acdc4509485b587f5e675510c4f2c63e90ff68a8"
96
-  version = "v1.1.0"
97
-
98 51
 [[projects]]
99 52
   name = "github.com/sirupsen/logrus"
100 53
   packages = ["."]
101 54
   revision = "c155da19408a8799da419ed3eeb0cb5db0ad5dbc"
102 55
   version = "v1.0.5"
103 56
 
104
-[[projects]]
105
-  name = "github.com/spf13/afero"
106
-  packages = [
107
-    ".",
108
-    "mem"
109
-  ]
110
-  revision = "63644898a8da0bc22138abf860edaf5277b6102e"
111
-  version = "v1.1.0"
112
-
113
-[[projects]]
114
-  name = "github.com/spf13/cast"
115
-  packages = ["."]
116
-  revision = "8965335b8c7107321228e3e3702cab9832751bac"
117
-  version = "v1.2.0"
118
-
119
-[[projects]]
120
-  branch = "master"
121
-  name = "github.com/spf13/jwalterweatherman"
122
-  packages = ["."]
123
-  revision = "7c0cea34c8ece3fbeb2b27ab9b59511d360fb394"
124
-
125
-[[projects]]
126
-  name = "github.com/spf13/pflag"
127
-  packages = ["."]
128
-  revision = "583c0c0531f06d5278b7d917446061adc344b5cd"
129
-  version = "v1.0.1"
130
-
131
-[[projects]]
132
-  name = "github.com/spf13/viper"
133
-  packages = ["."]
134
-  revision = "b5e8006cbee93ec955a89ab31e0e3ce3204f3736"
135
-  version = "v1.0.2"
136
-
137 57
 [[projects]]
138 58
   name = "github.com/ugorji/go"
139 59
   packages = ["codec"]
@@ -155,31 +75,12 @@
155 75
   ]
156 76
   revision = "79b0c6888797020a994db17c8510466c72fe75d9"
157 77
 
158
-[[projects]]
159
-  name = "golang.org/x/text"
160
-  packages = [
161
-    "internal/gen",
162
-    "internal/triegen",
163
-    "internal/ucd",
164
-    "transform",
165
-    "unicode/cldr",
166
-    "unicode/norm"
167
-  ]
168
-  revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0"
169
-  version = "v0.3.0"
170
-
171 78
 [[projects]]
172 79
   name = "gopkg.in/go-playground/validator.v8"
173 80
   packages = ["."]
174 81
   revision = "5f1438d3fca68893a817e4a66806cea46a9e4ebf"
175 82
   version = "v8.18.2"
176 83
 
177
-[[projects]]
178
-  name = "gopkg.in/ini.v1"
179
-  packages = ["."]
180
-  revision = "6529cf7c58879c08d927016dde4477f18a0634cb"
181
-  version = "v1.36.0"
182
-
183 84
 [[projects]]
184 85
   name = "gopkg.in/yaml.v2"
185 86
   packages = ["."]
@@ -189,6 +90,6 @@
189 90
 [solve-meta]
190 91
   analyzer-name = "dep"
191 92
   analyzer-version = 1
192
-  inputs-digest = "189c9df81b72ddb72fa7c1b56c60dc172855975aa186420308ebe5ed25f83f76"
93
+  inputs-digest = "69a38d98563bce4ac32cfa2afc36aa3298629f41568f13a4b6d3d18d97b22f67"
193 94
   solver-name = "gps-cdcl"
194 95
   solver-version = 1

+ 8
- 4
request/request.go View File

@@ -14,32 +14,36 @@ type Checker interface {
14 14
 
15 15
 func ParseSuccess(ctx *gin.Context, r interface{}, fs ...func() error) bool {
16 16
 	if r != nil {
17
-		if Error(ctx, http.StatusBadRequest, ctx.ShouldBind(r)) {
17
+		if Fail(ctx, http.StatusBadRequest, ctx.ShouldBind(r)) {
18 18
 			return false
19 19
 		}
20 20
 
21 21
 		if checker, ok := r.(Checker); ok {
22
-			return !Error(ctx, http.StatusBadRequest, checker.Check())
22
+			return !Fail(ctx, http.StatusBadRequest, checker.Check())
23 23
 		}
24 24
 	}
25
+
25 26
 	for _, f := range fs {
26
-		if Error(ctx, http.StatusBadRequest, f()) {
27
+		if Fail(ctx, http.StatusBadRequest, f()) {
27 28
 			return false
28 29
 		}
29 30
 	}
31
+
30 32
 	return true
31 33
 }
32 34
 
33
-func Error(ctx *gin.Context, status int, err error) bool {
35
+func Fail(ctx *gin.Context, status int, err error) bool {
34 36
 	if err == nil {
35 37
 		return false
36 38
 	}
39
+
37 40
 	ctx.JSON(status, gin.H{"msg": err.Error()})
38 41
 
39 42
 	if status == http.StatusInternalServerError {
40 43
 		_, file, line, _ := runtime.Caller(1)
41 44
 		logrus.WithField("err", err).Errorf("file:%s line:%d", file, line)
42 45
 	}
46
+
43 47
 	return true
44 48
 }
45 49