Paul 6 anos atrás
commit
0efb9db8e3
6 arquivos alterados com 162 adições e 0 exclusões
  1. 16
    0
      .gitignore
  2. 61
    0
      Gopkg.lock
  3. 34
    0
      Gopkg.toml
  4. 41
    0
      utils/helper.go
  5. 9
    0
      utils/time.go
  6. 1
    0
      utils/unit.go

+ 16
- 0
.gitignore Ver arquivo

@@ -0,0 +1,16 @@
1
+# Created by .ignore support plugin (hsz.mobi)
2
+### Go template
3
+# Binaries for programs and plugins
4
+*.exe
5
+*.exe~
6
+*.dll
7
+*.so
8
+*.dylib
9
+
10
+# Test binary, build with `go test -c`
11
+*.test
12
+
13
+# Output of the go coverage tool, specifically when used with LiteIDE
14
+*.out
15
+
16
+/vendor/

+ 61
- 0
Gopkg.lock Ver arquivo

@@ -0,0 +1,61 @@
1
+# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
2
+
3
+
4
+[[projects]]
5
+  branch = "master"
6
+  name = "github.com/gin-contrib/sse"
7
+  packages = ["."]
8
+  revision = "22d885f9ecc78bf4ee5d72b937e4bbcdc58e8cae"
9
+
10
+[[projects]]
11
+  name = "github.com/gin-gonic/gin"
12
+  packages = [
13
+    ".",
14
+    "binding",
15
+    "render"
16
+  ]
17
+  revision = "d459835d2b077e44f7c9b453505ee29881d5d12d"
18
+  version = "v1.2"
19
+
20
+[[projects]]
21
+  name = "github.com/golang/protobuf"
22
+  packages = ["proto"]
23
+  revision = "925541529c1fa6821df4e44ce2723319eb2be768"
24
+  version = "v1.0.0"
25
+
26
+[[projects]]
27
+  name = "github.com/mattn/go-isatty"
28
+  packages = ["."]
29
+  revision = "0360b2af4f38e8d38c7fce2a9f4e702702d73a39"
30
+  version = "v0.0.3"
31
+
32
+[[projects]]
33
+  name = "github.com/ugorji/go"
34
+  packages = ["codec"]
35
+  revision = "b4c50a2b199d93b13dc15e78929cfb23bfdf21ab"
36
+  version = "v1.1.1"
37
+
38
+[[projects]]
39
+  branch = "master"
40
+  name = "golang.org/x/sys"
41
+  packages = ["unix"]
42
+  revision = "79b0c6888797020a994db17c8510466c72fe75d9"
43
+
44
+[[projects]]
45
+  name = "gopkg.in/go-playground/validator.v8"
46
+  packages = ["."]
47
+  revision = "5f1438d3fca68893a817e4a66806cea46a9e4ebf"
48
+  version = "v8.18.2"
49
+
50
+[[projects]]
51
+  name = "gopkg.in/yaml.v2"
52
+  packages = ["."]
53
+  revision = "5420a8b6744d3b0345ab293f6fcba19c978f1183"
54
+  version = "v2.2.1"
55
+
56
+[solve-meta]
57
+  analyzer-name = "dep"
58
+  analyzer-version = 1
59
+  inputs-digest = "1a2b10f3ec80fa4b6ad88156b737403ca45820640ec668e0b797538b6274d305"
60
+  solver-name = "gps-cdcl"
61
+  solver-version = 1

+ 34
- 0
Gopkg.toml Ver arquivo

@@ -0,0 +1,34 @@
1
+# Gopkg.toml example
2
+#
3
+# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
4
+# for detailed Gopkg.toml documentation.
5
+#
6
+# required = ["github.com/user/thing/cmd/thing"]
7
+# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
8
+#
9
+# [[constraint]]
10
+#   name = "github.com/user/project"
11
+#   version = "1.0.0"
12
+#
13
+# [[constraint]]
14
+#   name = "github.com/user/project2"
15
+#   branch = "dev"
16
+#   source = "github.com/myfork/project2"
17
+#
18
+# [[override]]
19
+#   name = "github.com/x/y"
20
+#   version = "2.4.0"
21
+#
22
+# [prune]
23
+#   non-go = false
24
+#   go-tests = true
25
+#   unused-packages = true
26
+
27
+
28
+[[constraint]]
29
+  name = "github.com/gin-gonic/gin"
30
+  version = "1.2.0"
31
+
32
+[prune]
33
+  go-tests = true
34
+  unused-packages = true

+ 41
- 0
utils/helper.go Ver arquivo

@@ -0,0 +1,41 @@
1
+package utils
2
+
3
+import (
4
+	"net/http"
5
+
6
+	"github.com/gin-gonic/gin"
7
+)
8
+
9
+func Must(i interface{}, err error) interface{} {
10
+	if err != nil {
11
+		panic(err)
12
+	}
13
+
14
+	return i
15
+}
16
+
17
+func Error(ctx *gin.Context, err error) error {
18
+	if err != nil {
19
+		ctx.JSON(http.StatusBadRequest, gin.H{"info": err.Error()})
20
+		return err
21
+	}
22
+	return nil
23
+}
24
+
25
+func Bool(ctx *gin.Context, boolean bool) bool {
26
+	if !boolean {
27
+		ctx.JSON(http.StatusBadRequest, gin.H{"info": "validate failed"})
28
+		return !boolean
29
+	}
30
+	return boolean
31
+}
32
+
33
+func Success(ctx *gin.Context, data ...interface{}) {
34
+	response := gin.H{
35
+		"info": "success",
36
+	}
37
+	if len(data) > 0 {
38
+		response["data"] = data[0]
39
+	}
40
+	ctx.JSON(http.StatusOK, response)
41
+}

+ 9
- 0
utils/time.go Ver arquivo

@@ -0,0 +1,9 @@
1
+package utils
2
+
3
+import "time"
4
+
5
+const format = "2006-01-02 15:04:05"
6
+
7
+func GetNow() string {
8
+	return time.Now().Format(format)
9
+}

+ 1
- 0
utils/unit.go Ver arquivo

@@ -0,0 +1 @@
1
+package utils