-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp.go
52 lines (43 loc) · 1.23 KB
/
http.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
package http
import (
"context"
"time"
)
// IRequest represents the basics an incoming request type needs to provide to process an incoming
// request, independent of any endpoint provider
type IRequest interface {
GetHeader(key string) string
GetBody() string
GetBodyAs(arg interface{}) error
GetMethod() string
GetID() string
GetURLParam(arg string) string
GetQueryParam(param string) string
}
// IResponse represents the basics needed to process a response to the user independent of any
// endpoint provider
type IResponse interface {
SetHeader(key, value string) error
GetHeader(key string) string
SetBody(arg interface{}) error
SetCode(code int) error
AddError(err ...string) error
AddMessage(msg ...string) error
SetData(arg interface{}) error
// Finish should set a flag that freezes the request in place, refusing other updates
Finish() error
}
// IContext represents the type that all controllers must support in order to process an HTTP
// request
type IContext interface {
GetRequest() IRequest
GetResponse() IResponse
AddError(err ...string)
AddMessage(message ...string)
// Return this request to the client
Send()
IsDone() bool
GetDoneChannel() chan bool
Started() time.Time
Context() context.Context
}