diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cbb9ab3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +static/bundle.go +spec.json diff --git a/Makefile b/Makefile index 09bb12c..717d436 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ clean: generate-spec: swagger generate spec -m --compact -o spec.json -build-static: +bundle-static: go-bindata -fs -pkg static -ignore .git -o static/bundle.go public/ schema/ spec.json test: diff --git a/go.mod b/go.mod index ec141c3..c0fc6de 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.14 require ( git.trj.tw/golang/argparse v1.0.1 git.trj.tw/golang/config-loader v1.0.1 + github.com/gabriel-vasile/mimetype v1.1.1 github.com/gin-gonic/gin v1.6.3 github.com/go-playground/validator/v10 v10.3.0 // indirect github.com/go-redis/redis v6.15.9+incompatible @@ -16,4 +17,5 @@ require ( github.com/onsi/ginkgo v1.14.0 // indirect golang.org/x/sys v0.0.0-20200805065543-0cf7623e9dbd // indirect google.golang.org/protobuf v1.25.0 // indirect + gopkg.in/yaml.v2 v2.3.0 ) diff --git a/go.sum b/go.sum index 0d0f5f3..ca0a0ec 100644 --- a/go.sum +++ b/go.sum @@ -17,6 +17,8 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7 github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= +github.com/gabriel-vasile/mimetype v1.1.1 h1:qbN9MPuRf3bstHu9zkI9jDWNfH//9+9kHxr9oRBBBOA= +github.com/gabriel-vasile/mimetype v1.1.1/go.mod h1:6CDPel/o/3/s4+bp6kIbsWATq8pmgOisOPG40CJa6To= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14= diff --git a/pkg/errors/errors.go b/pkg/errors/errors.go index 91c3c40..ae3bf16 100644 --- a/pkg/errors/errors.go +++ b/pkg/errors/errors.go @@ -27,6 +27,28 @@ func (e *APIError) Error() string { return s } +func (e *APIError) SetCode(code response.MessageCode) *APIError { + e = &APIError{ + status: e.status, + code: &code, + message: e.message, + } + return e +} + +func (e *APIError) SetMessage(s string) *APIError { + e = &APIError{ + status: e.status, + code: e.code, + message: s, + } + + return e +} + +func (e *APIError) Code() *response.MessageCode { return e.code } +func (e *APIError) Status() response.RespType { return e.status } + func New(status response.RespType, code ...response.MessageCode) *APIError { e := &APIError{ status: status, diff --git a/public/swagger/favicon-16x16.png b/public/swagger/favicon-16x16.png new file mode 100644 index 0000000..8b194e6 Binary files /dev/null and b/public/swagger/favicon-16x16.png differ diff --git a/public/swagger/favicon-32x32.png b/public/swagger/favicon-32x32.png new file mode 100644 index 0000000..249737f Binary files /dev/null and b/public/swagger/favicon-32x32.png differ diff --git a/public/swagger/index.html b/public/swagger/index.html new file mode 100644 index 0000000..89f8446 --- /dev/null +++ b/public/swagger/index.html @@ -0,0 +1,61 @@ + + + +
+ +