Przeglądaj źródła

add tcp request lib

Paul 6 lat temu
rodzic
commit
b5ce0a63b8
4 zmienionych plików z 111 dodań i 2 usunięć
  1. 12
    2
      request/go.mod
  2. 42
    0
      request/go.sum
  3. 6
    0
      request/tr/error.go
  4. 51
    0
      request/tr/tr.go

+ 12
- 2
request/go.mod Wyświetl plik

@@ -1,14 +1,24 @@
1 1
 module git.links123.net/links123.com/pkg/request
2 2
 
3 3
 require (
4
+	github.com/davecgh/go-spew v1.1.1 // indirect
4 5
 	github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7 // indirect
5 6
 	github.com/gin-gonic/gin v1.3.0
6
-	github.com/golang/protobuf v1.2.0 // indirect
7
+	github.com/json-iterator/go v1.1.5 // indirect
7 8
 	github.com/mattn/go-isatty v0.0.4 // indirect
9
+	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
10
+	github.com/modern-go/reflect2 v1.0.1 // indirect
11
+	github.com/onsi/gomega v1.4.2 // indirect
12
+	github.com/pmezard/go-difflib v1.0.0 // indirect
8 13
 	github.com/sirupsen/logrus v1.0.6
14
+	github.com/stretchr/testify v1.2.2 // indirect
9 15
 	github.com/ugorji/go/codec v0.0.0-20180831062425-e253f1f20942 // indirect
16
+	github.com/wpajqz/linker v0.0.0-20180920052826-c21901f38257
10 17
 	golang.org/x/crypto v0.0.0-20180910181607-0e37d006457b // indirect
18
+	golang.org/x/net v0.0.0-20181102091132-c10e9556a7bc // indirect
11 19
 	golang.org/x/sys v0.0.0-20180918153733-ee1b12c67af4 // indirect
20
+	gopkg.in/airbrake/gobrake.v2 v2.0.9 // indirect
21
+	gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 // indirect
22
+	gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
12 23
 	gopkg.in/go-playground/validator.v8 v8.18.2 // indirect
13
-	gopkg.in/yaml.v2 v2.2.1 // indirect
14 24
 )

+ 42
- 0
request/go.sum Wyświetl plik

@@ -1,21 +1,63 @@
1
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3
+github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
4
+github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
1 5
 github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7 h1:AzN37oI0cOS+cougNAV9szl6CVoj2RYwzS3DpUQNtlY=
2 6
 github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s=
3 7
 github.com/gin-gonic/gin v1.3.0 h1:kCmZyPklC0gVdL728E6Aj20uYBJV93nj/TkwBTKhFbs=
4 8
 github.com/gin-gonic/gin v1.3.0/go.mod h1:7cKuhb5qV2ggCFctp2fJQ+ErvciLZrIeoOSOm6mUr7Y=
9
+github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
5 10
 github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
6 11
 github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
12
+github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
13
+github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
14
+github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
15
+github.com/json-iterator/go v1.1.5 h1:gL2yXlmiIo4+t+y32d4WGwOjKGYcGOuyrg46vadswDE=
16
+github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
7 17
 github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs=
8 18
 github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
19
+github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
20
+github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
21
+github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
22
+github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
23
+github.com/onsi/ginkgo v1.6.0 h1:Ix8l273rp3QzYgXSR+c8d1fTG7UPgYkOSELPhiY/YGw=
24
+github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
25
+github.com/onsi/gomega v1.4.2 h1:3mYCb7aPxS/RU7TI1y4rkEn1oKmPRjNJLNEXgw7MH2I=
26
+github.com/onsi/gomega v1.4.2/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
27
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
28
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
9 29
 github.com/sirupsen/logrus v1.0.6 h1:hcP1GmhGigz/O7h1WVUM5KklBp1JoNS9FggWKdj/j3s=
10 30
 github.com/sirupsen/logrus v1.0.6/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc=
31
+github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
32
+github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
11 33
 github.com/ugorji/go/codec v0.0.0-20180831062425-e253f1f20942 h1:CZORS/4d6i+5FKSAtbRIjlElV2BAFYv/bokcaEVUimQ=
12 34
 github.com/ugorji/go/codec v0.0.0-20180831062425-e253f1f20942/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
35
+github.com/wpajqz/go-sdk v0.0.0-20180819022515-c5611acbd333/go.mod h1:8Z5OwaDGrREAqXYMHp9WVhDIkZdeJFfNbUyjYQGRg8U=
36
+github.com/wpajqz/linker v0.0.0-20180818151004-5d64412a1130/go.mod h1:1LpNSex7lqvQi8t5uj9LBLKsvxfm3HK2j6o5Ht3BGmQ=
37
+github.com/wpajqz/linker v0.0.0-20180920052826-c21901f38257 h1:i5vHdYSGYZr6fJ2S/MTY8PCvUAZCks5wbZcmBgmNKGc=
38
+github.com/wpajqz/linker v0.0.0-20180920052826-c21901f38257/go.mod h1:qDGjG+ES9GK54nkt/8PE3SbGtKyZI0U0XSU7B8hvhqM=
13 39
 golang.org/x/crypto v0.0.0-20180910181607-0e37d006457b h1:2b9XGzhjiYsYPnKXoEfL7klWZQIt8IfyRCz62gCqqlQ=
14 40
 golang.org/x/crypto v0.0.0-20180910181607-0e37d006457b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
41
+golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
42
+golang.org/x/net v0.0.0-20181102091132-c10e9556a7bc h1:ZMCWScCvS2fUVFw8LOpxyUUW5qiviqr4Dg5NdjLeiLU=
43
+golang.org/x/net v0.0.0-20181102091132-c10e9556a7bc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
44
+golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
45
+golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
15 46
 golang.org/x/sys v0.0.0-20180918153733-ee1b12c67af4 h1:h8ij2QOL81JqJ/Vi5Ru+hl4a1yct8+XDGrgBhG0XbuE=
16 47
 golang.org/x/sys v0.0.0-20180918153733-ee1b12c67af4/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
48
+golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
49
+gopkg.in/airbrake/gobrake.v2 v2.0.9 h1:7z2uVWwn7oVeeugY1DtlPAy5H+KYgB1KeKTnqjNatLo=
50
+gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U=
17 51
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
52
+gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
53
+gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
54
+gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 h1:OAj3g0cR6Dx/R07QgQe8wkA9RNjB2u4i700xBkIT4e0=
55
+gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2/go.mod h1:Xk6kEKp8OKb+X14hQBKWaSkCsqBpgog8nAV2xsGOxlo=
56
+gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM=
57
+gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE=
18 58
 gopkg.in/go-playground/validator.v8 v8.18.2 h1:lFB4DoMU6B626w8ny76MV7VX6W2VHct2GVOI3xgiMrQ=
19 59
 gopkg.in/go-playground/validator.v8 v8.18.2/go.mod h1:RX2a/7Ha8BgOhfk7j780h4/u/RRjR0eouCJSH80/M2Y=
60
+gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
61
+gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
20 62
 gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
21 63
 gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

+ 6
- 0
request/tr/error.go Wyświetl plik

@@ -0,0 +1,6 @@
1
+package tr
2
+
3
+// TCPError response tcp error
4
+type TCPError struct {
5
+	Msg string `json:"msg" example:"status bad request"`
6
+}

+ 51
- 0
request/tr/tr.go Wyświetl plik

@@ -0,0 +1,51 @@
1
+package tr
2
+
3
+import (
4
+	"runtime"
5
+
6
+	"github.com/sirupsen/logrus"
7
+	"github.com/wpajqz/linker"
8
+)
9
+
10
+type Checker interface {
11
+	Check() error
12
+}
13
+
14
+func ParseParamFail(ctx linker.Context, param interface{}, fs ...func() error) bool {
15
+	if param != nil {
16
+		if Fail(ctx, linker.StatusBadRequest, ctx.ParseParam(param)) {
17
+			return true
18
+		}
19
+
20
+		if checker, ok := param.(Checker); ok {
21
+			return Fail(ctx, linker.StatusBadRequest, checker.Check())
22
+		}
23
+	}
24
+
25
+	for _, f := range fs {
26
+		if Fail(ctx, linker.StatusBadRequest, f()) {
27
+			return true
28
+		}
29
+	}
30
+
31
+	return false
32
+}
33
+
34
+func Fail(ctx linker.Context, status int, err error) bool {
35
+	if err == nil {
36
+		return false
37
+	}
38
+
39
+	ctx.Error(status, err.Error())
40
+
41
+	if status == linker.StatusInternalServerError {
42
+		_, file, line, _ := runtime.Caller(1)
43
+		logrus.WithField("err", err).Errorf("file:%s line:%d", file, line)
44
+	}
45
+
46
+	return true
47
+}
48
+
49
+func Success(ctx linker.Context, data interface{}) {
50
+	ctx.Success(data)
51
+}