-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtypes.go
150 lines (122 loc) · 3 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package service
import (
"context"
"io"
"net/http"
"net/url"
"github.com/gorilla/mux"
"github.com/gorilla/websocket"
"github.com/spf13/afero"
)
type Redirect string
type TemporaryRedirect Redirect
type PermanentRedirect Redirect
type Handler func(ctx Context) (interface{}, error)
type RouteAuthHandler struct {
Validator Handler
GC Handler
}
type RawData struct {
ContentType string
Data []byte
}
type RawStream struct {
ContentType string
Stream io.ReadCloser
}
type RawRouteDefinition struct {
Host string
Path string
PathPrefix string
Vars Variables
Scope []string
Auth RouteAuthHandler
Handler Handler
RawResponse bool
}
type LowLevelDefinition struct {
Path string
PathPrefix string
Handler func(w http.ResponseWriter, r *http.Request)
}
type RouteDefinition struct {
Host string
Path string
Vars Variables
Scope []string
Auth RouteAuthHandler
Handler Handler
RawResponse bool
}
type AssetsDefinition struct {
Host string
Path string
Vars Variables
Scope []string
Auth RouteAuthHandler
FileSystem afero.Fs
Directory string
SinglePageApplication bool
BeforeServe func(w http.ResponseWriter)
}
type HeadlessAssetsDefinition struct {
FileSystem afero.Fs
Directory string
SinglePageApplication bool
BeforeServe func(w http.ResponseWriter)
}
type WebSocketHandler interface {
In()
Out()
}
type Variables struct {
Required []string
Optional []string
}
type Context interface {
HandleWith(handler Handler) error
HandleAuth(Handler) error
HandleCleanup(Handler) error
Request() *http.Request
Writer() http.ResponseWriter
ParseBody(obj interface{}) error
RawResponse() bool
SetRawResponse(val bool)
Variables() map[string]interface{}
SetVariable(key string, val interface{})
Body() []byte
SetBody([]byte)
GetStringVariable(key string) (string, error)
GetStringArrayVariable(key string) ([]string, error)
GetStringMapVariable(key string) (map[string]interface{}, error)
GetIntVariable(key string) (int, error)
}
type WebSocketDefinition struct {
Host string
Path string
Vars Variables
Scope []string
Auth RouteAuthHandler
NewHandler func(ctx Context, conn *websocket.Conn) WebSocketHandler
}
type Service interface {
Context() context.Context
Start()
Stop()
Wait() error
Error() error
/********************************/
GET(*RouteDefinition)
PUT(*RouteDefinition)
POST(*RouteDefinition)
DELETE(*RouteDefinition)
PATCH(*RouteDefinition)
ALL(*RouteDefinition)
Raw(*RawRouteDefinition) *mux.Route
LowLevel(*LowLevelDefinition) *mux.Route
WebSocket(*WebSocketDefinition)
ServeAssets(*AssetsDefinition)
AssetHandler(*HeadlessAssetsDefinition, Context) (interface{}, error)
LowLevelAssetHandler(*HeadlessAssetsDefinition, http.ResponseWriter, *http.Request) error
GetListenAddress() (*url.URL, error)
}