Use generator to generate exceptions from yaml

Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
2026-01-21 13:48:37 +08:00
parent e4329dfc2b
commit ac428946e7
40 changed files with 291 additions and 149 deletions

View File

@@ -0,0 +1,55 @@
package exception
import (
"fmt"
)
// 12 chars len
// :1=status
// :3=service
// :2=endpoint
// :1=common/specific
// :5=original
type Builder struct {
Status string
Service string
Endpoint string
Type string
Original string
}
func (self *Builder) SetStatus(s string) *Builder {
self.Status = s
return self
}
func (self *Builder) SetService(s string) *Builder {
self.Service = s
return self
}
func (self *Builder) SetEndpoint(s string) *Builder {
self.Endpoint = s
return self
}
func (self *Builder) SetType(s string) *Builder {
self.Type = s
return self
}
func (self *Builder) SetOriginal(s string) *Builder {
self.Original = s
return self
}
func (self *Builder) Build() string {
return fmt.Sprintf("%s%s%s%s%s",
self.Status,
self.Service,
self.Endpoint,
self.Type,
self.Original,
)
}

View File

@@ -0,0 +1,13 @@
// Code generated by gen-exception; DO NOT EDIT.
package exception
const (
CommonErrorInvalidInput = "00001"
CommonErrorUnauthorized = "00002"
CommonErrorInternal = "00003"
CommonErrorPermissionDenied = "00004"
CommonErrorUuidParseFailed = "00005"
CommonErrorDatabase = "00006"
CommonErrorMissingUserId = "00007"
CommonErrorUserNotFound = "00008"
)

View File

@@ -0,0 +1,10 @@
common:
error:
invalid_input: "00001"
unauthorized: "00002"
internal: "00003"
permission_denied: "00004"
uuid_parse_failed: "00005"
database: "00006"
missing_user_id: "00007"
user_not_found: "00008"

View File

@@ -0,0 +1,23 @@
endpoint:
auth:
service:
redirect: "01"
magic: "02"
token: "03"
refresh: "04"
exchange: "05"
event:
service:
info: "01"
checkin: "02"
checkin_query: "03"
checkin_submit: "04"
user:
service:
info: "01"
update: "02"
list: "03"
full: "04"
create: "05"
middleware:
service: "01"

View File

@@ -0,0 +1,5 @@
middleware:
gin_logger: "901"
jwt: "902"
permission: "903"
api_version: "904"

View File

@@ -0,0 +1,4 @@
service:
auth: "001"
user: "002"
event: "003"

View File

@@ -0,0 +1,27 @@
api:
version:
not_found: "00001"
auth:
redirect:
token_invalid: "00001"
client_not_found: "00002"
uri_mismatch: "00003"
invalid_uri: "00004"
magic:
turnstile_failed: "00001"
code_gen_failed: "00002"
invalid_external_url: "00003"
invalid_email_config: "00004"
token:
invalid_token: "00001"
gen_failed: "00002"
refresh:
invalid_token: "00001"
renew_failed: "00002"
exchange:
get_user_id_failed: "00001"
code_gen_failed: "00002"
invalid_redirect_uri: "00003"
user:
list:
meilisearch_failed: "00001"

View File

@@ -0,0 +1,5 @@
status:
success: "2"
user: "4"
server: "5"
client: "6"

View File

@@ -0,0 +1,3 @@
type:
common: "1"
specific: "0"

View File

@@ -0,0 +1,20 @@
// Code generated by gen-exception; DO NOT EDIT.
package exception
const (
EndpointAuthServiceExchange = "05"
EndpointAuthServiceRedirect = "01"
EndpointAuthServiceMagic = "02"
EndpointAuthServiceToken = "03"
EndpointAuthServiceRefresh = "04"
EndpointEventServiceCheckinQuery = "03"
EndpointEventServiceCheckinSubmit = "04"
EndpointEventServiceInfo = "01"
EndpointEventServiceCheckin = "02"
EndpointUserServiceList = "03"
EndpointUserServiceFull = "04"
EndpointUserServiceCreate = "05"
EndpointUserServiceInfo = "01"
EndpointUserServiceUpdate = "02"
EndpointMiddlewareService = "01"
)

View File

@@ -0,0 +1,9 @@
// Code generated by gen-exception; DO NOT EDIT.
package exception
const (
MiddlewareGinLogger = "901"
MiddlewareJwt = "902"
MiddlewarePermission = "903"
MiddlewareApiVersion = "904"
)

View File

@@ -0,0 +1,8 @@
// Code generated by gen-exception; DO NOT EDIT.
package exception
const (
ServiceUser = "002"
ServiceEvent = "003"
ServiceAuth = "001"
)

View File

@@ -0,0 +1,22 @@
// Code generated by gen-exception; DO NOT EDIT.
package exception
const (
ApiVersionNotFound = "00001"
AuthRefreshInvalidToken = "00001"
AuthRefreshRenewFailed = "00002"
AuthExchangeGetUserIdFailed = "00001"
AuthExchangeCodeGenFailed = "00002"
AuthExchangeInvalidRedirectUri = "00003"
AuthRedirectClientNotFound = "00002"
AuthRedirectUriMismatch = "00003"
AuthRedirectInvalidUri = "00004"
AuthRedirectTokenInvalid = "00001"
AuthMagicCodeGenFailed = "00002"
AuthMagicInvalidExternalUrl = "00003"
AuthMagicInvalidEmailConfig = "00004"
AuthMagicTurnstileFailed = "00001"
AuthTokenInvalidToken = "00001"
AuthTokenGenFailed = "00002"
UserListMeilisearchFailed = "00001"
)

View File

@@ -0,0 +1,9 @@
// Code generated by gen-exception; DO NOT EDIT.
package exception
const (
StatusClient = "6"
StatusSuccess = "2"
StatusUser = "4"
StatusServer = "5"
)

View File

@@ -0,0 +1,7 @@
// Code generated by gen-exception; DO NOT EDIT.
package exception
const (
TypeCommon = "1"
TypeSpecific = "0"
)