-
Notifications
You must be signed in to change notification settings - Fork 12
/
types.go
133 lines (115 loc) · 4.06 KB
/
types.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package gogo
import (
"net/http"
"net/http/httputil"
"github.com/dolab/gogo/pkgs/interceptors"
"github.com/dolab/httpdispatch"
)
// A Middleware represents request filters or resource handler
//
// NOTE: It is the filter's responsibility to invoke ctx.Next() for chainning.
type Middleware func(ctx *Context)
// A Configer represents config interface
type Configer interface {
RunMode() RunMode
RunName() string
Filename() string
SetMode(mode RunMode)
Section() *SectionConfig
UnmarshalJSON(v interface{}) error
UnmarshalYAML(v interface{}) error
// for middlewares
Interceptors() interceptors.Configer
LoadInterceptors() error
}
// A Grouper represents router interface
type Grouper interface {
NewGroup(prefix string, filters ...Middleware) Grouper
SetHandler(handler Handler)
Use(filters ...Middleware)
OPTIONS(uri string, filter Middleware)
HEAD(uri string, filter Middleware)
POST(uri string, filter Middleware)
GET(uri string, filter Middleware)
PUT(uri string, filter Middleware)
PATCH(uri string, filter Middleware)
DELETE(uri string, filter Middleware)
Any(uri string, filter Middleware)
Static(uri, root string)
Resource(uri string, resource interface{}) Grouper
Proxy(method, uri string, proxy *httputil.ReverseProxy)
HandlerFunc(method, uri string, fn http.HandlerFunc)
Handler(method, uri string, handler http.Handler)
Handle(method, uri string, filter Middleware)
MountRPC(method string, rpc RPCServicer)
MockHandle(method, uri string, recorder http.ResponseWriter, filter Middleware)
}
// A Servicer represents application interface
type Servicer interface {
Init(config Configer, group Grouper)
Middlewares()
Resources()
}
// RPCServicer is the interface for rpc serve. It wraps HTTP handlers with
// additional methods for accessing metadata about the service.
type RPCServicer interface {
// ProtocGenGogoVersion is the semantic version string of the version of
// protoc-gen-gogo used to generate service.
ProtocGenGogoVersion() string
// ServiceRegistry returns a rpc method name to handlers map.
ServiceRegistry(prefix string) map[string]Middleware
// ServiceNames returns all rpc services registered.
ServiceNames() []string
// ServiceDescriptor returns gzipped bytes describing the .proto file that
// this service was generated from. Once unzipped, the bytes can be
// unmarshalled as a
// github.com/golang/protobuf/protoc-gen-go/descriptor.FileDescriptorProto.
//
// The returned integer is the index of this particular service within that
// FileDescriptorProto's 'Service' slice of ServiceDescriptorProtos. This is a
// low-level field, expected to be used for reflection.
ServiceDescriptor() ([]byte, int)
}
// A Handler represents handler interface
type Handler interface {
http.Handler
Handle(string, string, httpdispatch.Handler)
ServeFiles(string, http.FileSystem)
}
// A Responser represents HTTP response interface
type Responser interface {
http.ResponseWriter
http.Flusher
HeaderFlushed() bool // whether response header has been sent?
FlushHeader() // send response header only if it has not sent
Status() int // response status code
Size() int // return the size of response body
Hijack(http.ResponseWriter) // hijack response with new http.ResponseWriter
}
// A StatusCoder represents HTTP response status code interface.
// it is useful for custom response data with response status code
type StatusCoder interface {
StatusCode() int
}
// A Logger represents log interface
type Logger interface {
New(requestID string) Logger
Reuse(l Logger)
RequestID() string
SetLevelByName(level string) error
SetColor(color bool)
Print(v ...interface{})
Printf(format string, v ...interface{})
Debug(v ...interface{})
Debugf(format string, v ...interface{})
Info(v ...interface{})
Infof(format string, v ...interface{})
Warn(v ...interface{})
Warnf(format string, v ...interface{})
Error(v ...interface{})
Errorf(format string, v ...interface{})
Fatal(v ...interface{})
Fatalf(format string, v ...interface{})
Panic(v ...interface{})
Panicf(format string, v ...interface{})
}