parent
6cdc720ec4
commit
3089fbf1e6
@ -1,6 +1,8 @@
|
||||
package database
|
||||
|
||||
import "context"
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type Database interface {
|
||||
QueryByQQNumber(ctx context.Context, qqNumber int64) ([]Model, error)
|
||||
|
@ -10,7 +10,7 @@ var configPath string
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&configPath, "config", "../config.yaml", "config file path")
|
||||
flag.Parse()
|
||||
flag.Parse()
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
@ -9,14 +9,14 @@ import (
|
||||
|
||||
var (
|
||||
OK = errors.New("ok")
|
||||
UnknownError = errors.New("unknown error")
|
||||
InvalidParameterError = errors.New("invalid parameter error")
|
||||
QueryFailedError = errors.New("query failed error")
|
||||
)
|
||||
|
||||
var errorMap = map[error]int{
|
||||
OK: 0,
|
||||
UnknownError: 10001,
|
||||
InvalidParameterError: 10002,
|
||||
InvalidParameterError: 10001,
|
||||
QueryFailedError: 10002,
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
@ -31,8 +31,7 @@ func NewResponse(ctx echo.Context, err error, data interface{}) error {
|
||||
}
|
||||
code, ok := errorMap[err]
|
||||
if !ok {
|
||||
err = UnknownError
|
||||
code = errorMap[err]
|
||||
code = 10000
|
||||
}
|
||||
return ctx.JSONPretty(http.StatusOK, &Response{
|
||||
Code: code,
|
||||
|
@ -37,7 +37,7 @@ func NewService(configPath string) *Service {
|
||||
func (svc *Service) loadRouter() {
|
||||
instance := svc.instance
|
||||
instance.HTTPErrorHandler = func(err error, ctx echo.Context) {
|
||||
_ = NewResponse(ctx, UnknownError, err)
|
||||
_ = NewResponse(ctx, err, nil)
|
||||
}
|
||||
instance.Static("/", "../website/build")
|
||||
apiGroup := instance.Group("/api")
|
||||
|
Loading…
x
Reference in New Issue
Block a user