-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.go
87 lines (63 loc) · 2.15 KB
/
base.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright 2020 Lingfei Kong <colin404@foxmail.com>. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package code
//go:generate codegen -type=int
//go:generate codegen -type=int -doc -output ../../../docs/guide/zh-CN/api/error_code_generated.md
// Common: basic errors.
// Code must start with 1xxxxx.
const (
// ErrSuccess - 200: OK.
ErrSuccess int = iota + 100001
// ErrUnknown - 500: Internal server error.
ErrUnknown
// ErrBind - 400: Error occurred while binding the request body to the struct.
ErrBind
// ErrValidation - 400: Validation failed.
ErrValidation
// ErrTokenInvalid - 401: Token invalid.
ErrTokenInvalid
// ErrPageNotFound - 404: Page not found.
ErrPageNotFound
)
// common: database errors.
const (
// ErrDatabase - 500: Database error.
ErrDatabase int = iota + 100101
)
// common: authorization and authentication errors.
const (
// ErrEncrypt - 401: Error occurred while encrypting the user password.
ErrEncrypt int = iota + 100201
// ErrSignatureInvalid - 401: Signature is invalid.
ErrSignatureInvalid
// ErrExpired - 401: Token expired.
ErrExpired
// ErrInvalidAuthHeader - 401: Invalid authorization header.
ErrInvalidAuthHeader
// ErrMissingHeader - 401: The `Authorization` header was empty.
ErrMissingHeader
// ErrPasswordIncorrect - 401: Password was incorrect.
ErrPasswordIncorrect
// PermissionDenied - 403: Permission denied.
ErrPermissionDenied
)
// common: encode/decode errors.
const (
// ErrEncodingFailed - 500: Encoding failed due to an error with the data.
ErrEncodingFailed int = iota + 100301
// ErrDecodingFailed - 500: Decoding failed due to an error with the data.
ErrDecodingFailed
// ErrInvalidJSON - 500: Data is not valid JSON.
ErrInvalidJSON
// ErrEncodingJSON - 500: JSON data could not be encoded.
ErrEncodingJSON
// ErrDecodingJSON - 500: JSON data could not be decoded.
ErrDecodingJSON
// ErrInvalidYaml - 500: Data is not valid Yaml.
ErrInvalidYaml
// ErrEncodingYaml - 500: Yaml data could not be encoded.
ErrEncodingYaml
// ErrDecodingYaml - 500: Yaml data could not be decoded.
ErrDecodingYaml
)