-
Notifications
You must be signed in to change notification settings - Fork 0
/
server-ice.go
100 lines (81 loc) · 2.98 KB
/
server-ice.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
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* Copyright (c) 2024.
* Created by Andy Pangaribuan <https://github.com/apangaribuan>.
*
* This product is protected by copyright and distributed under
* licenses restricting copying, distribution and decompilation.
* All Rights Reserved.
*/
package server
import (
"mime/multipart"
"github.com/andypangaribuan/gmod/clog"
"google.golang.org/grpc"
)
type server interface {
FuseG(grpcPort int, routes func(router RouterG))
FuseR(restPort int, routes func(router RouterR))
FuseGR(grpcPort int, grpcRoutes func(router RouterG), restPort int, restRoutes func(router RouterR))
}
type RouterR interface {
AutoRecover(autoRecover bool)
PrintOnError(printOnError bool)
Unrouted(handler func(ctx FuseRContext, method, path, url string) any)
ErrorHandler(catcher func(ctx FuseRContext, err error) any)
Endpoints(regulator func(regulator FuseRRegulator), auth func(FuseRContext) any, pathHandlers map[string][]func(FuseRContext) any)
}
type RouterG interface {
AutoRecover(autoRecover bool)
Server() *grpc.Server
RunHealthCheck()
}
type FuseRContext interface {
Clog() clog.Instance
Auth(obj ...any) any
UserId(id ...any) any
PartnerId(id ...any) any
SetFiles(files map[string]string)
ReqHeader() *map[string]string
ReqParam() *map[string]string
ReqQuery() *map[string]string
ReqForm() *map[string][]string
ReqFile() *map[string][]*multipart.FileHeader
GetHeader(key string, dval ...string) *string
ReqParser(header any, body any) error
ReqParserPQF(param any, query any, form any) error
LastResponse() (val any, meta ResponseMeta)
R200OK(val any, opt ...ResponseOpt) any
R201Created(val any, opt ...ResponseOpt) any
R202Accepted(val any, opt ...ResponseOpt) any
R204NoContent(val any, opt ...ResponseOpt) any
R301MovedPermanently(val any, opt ...ResponseOpt) any
R307TemporaryRedirect(val any, opt ...ResponseOpt) any
R308PermanentRedirect(val any, opt ...ResponseOpt) any
R400BadRequest(val any, opt ...ResponseOpt) any
R401Unauthorized(val any, opt ...ResponseOpt) any
R403Forbidden(val any, opt ...ResponseOpt) any
R404NotFound(val any, opt ...ResponseOpt) any
R406NotAcceptable(val any, opt ...ResponseOpt) any
R412PreconditionFailed(val any, opt ...ResponseOpt) any
R418Teapot(val any, opt ...ResponseOpt) any
R428PreconditionRequired(val any, opt ...ResponseOpt) any
R500InternalServerError(err error, opt ...ResponseOpt) any
R503ServiceUnavailable(val any, opt ...ResponseOpt) any
}
type FuseRContextBuilder interface {
Build() FuseRContext
}
type FuseRRegulator interface {
Next() (next bool, handler func(ctx FuseRContext) any)
IsHandler(handler func(ctx FuseRContext) any) bool
Call(handler func(ctx FuseRContext) any, opt ...FuseRCallOpt) (res any, meta ResponseMeta, raw bool)
CallOpt() FuseRCallOpt
Endpoint() string
Recover()
}
type FuseRCallOpt interface {
OverrideHeader(val map[string]string) FuseRCallOpt
OverrideParam(val map[string]string) FuseRCallOpt
OverrideQuery(val map[string]string) FuseRCallOpt
OverrideForm(val map[string][]string) FuseRCallOpt
}