-
Notifications
You must be signed in to change notification settings - Fork 0
/
endpoint.go
38 lines (32 loc) · 1.05 KB
/
endpoint.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
package mock
import (
"encoding/json"
)
type endpointConfig struct {
Path string `json:"path"`
Method string `json:"method"`
ResponseBody json.RawMessage `json:"response_body"`
StringBody string `json:"string_body"`
ContentType string `json:"content_type"`
Response int `json:"response"`
Header map[string]string `json:"header"`
Name string `json:"-"`
ReplyDelay int `json:"reply_delay"`
}
type endpoint struct {
config endpointConfig
customRequestHandler func(string, string, string)
}
//IEndpoint interface
type IEndpoint interface {
RequestHandler(handler func(string, string, string)) IEndpoint
Reply(handler func(IReply)) IEndpoint
}
func (endpoint *endpoint) RequestHandler(handler func(string, string, string)) IEndpoint {
endpoint.customRequestHandler = handler
return endpoint
}
func (endpoint *endpoint) Reply(handler func(IReply)) IEndpoint {
handler(&reply{config: &endpoint.config})
return endpoint
}