-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroute.go
More file actions
43 lines (36 loc) · 820 Bytes
/
route.go
File metadata and controls
43 lines (36 loc) · 820 Bytes
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
package reverseproxy
import (
"net/http"
"strings"
)
type Route struct {
Method []string
Path string
RewritePath string
RequestHeader http.Header
ModifyResponse ResponseModifier
}
func NewRoute(methods, path string) Route {
return Route{
Method: methodStringToSlice(methods),
Path: path,
}
}
func (r Route) SetRewritePath(path string) Route {
r.RewritePath = path
return r
}
func (r Route) SetRequestHeader(header http.Header) Route {
r.RequestHeader = header
return r
}
func (r Route) SetModifyResponse(modifier ResponseModifier) Route {
r.ModifyResponse = modifier
return r
}
func methodStringToSlice(methods string) []string {
if methods == "*" {
return []string{"GET", "HEAD", "OPTIONS", "POST", "PUT", "PATCH", "DELETE"}
}
return strings.Split(methods, "|")
}