-
Notifications
You must be signed in to change notification settings - Fork 563
/
router.go
70 lines (58 loc) · 2.6 KB
/
router.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
// Package router defines some interfaces for router adapters
package router
import (
"context"
"github.com/devopsfaith/krakend/config"
http "github.com/devopsfaith/krakend/transport/http/server"
)
// Router sets up the public layer exposed to the users
type Router interface {
Run(config.ServiceConfig)
}
// RouterFunc type is an adapter to allow the use of ordinary functions as routers.
// If f is a function with the appropriate signature, RouterFunc(f) is a Router that calls f.
type RouterFunc func(config.ServiceConfig)
// Run implements the Router interface
func (f RouterFunc) Run(cfg config.ServiceConfig) { f(cfg) }
// Factory creates new routers
type Factory interface {
New() Router
NewWithContext(context.Context) Router
}
// ToHTTPError translates an error into a HTTP status code
// Deprecated: ToHTTPError is deprecated
type ToHTTPError http.ToHTTPError
// DefaultToHTTPError is a ToHTTPError transalator that always returns an
// internal server error
// Deprecated: DefaultToHTTPError is deprecated
var DefaultToHTTPError = http.DefaultToHTTPError
const (
// HeaderCompleteResponseValue is the value of the CompleteResponseHeader
// if the response is complete
// Deprecated: HeaderCompleteResponseValue is deprecated
HeaderCompleteResponseValue = http.HeaderCompleteResponseValue
// HeaderIncompleteResponseValue is the value of the CompleteResponseHeader
// if the response is not complete
// Deprecated: HeaderIncompleteResponseValue is deprecated
HeaderIncompleteResponseValue = http.HeaderIncompleteResponseValue
)
var (
// CompleteResponseHeaderName is the header to flag incomplete responses to the client
// Deprecated: HeaderIncompleteResponseValue is deprecated
CompleteResponseHeaderName = http.CompleteResponseHeaderName
// HeadersToSend are the headers to pass from the router request to the proxy
// Deprecated: HeadersToSend is deprecated
HeadersToSend = http.HeadersToSend
// UserAgentHeaderValue is the value of the User-Agent header to add to the proxy request
// Deprecated: UserAgentHeaderValue is deprecated
UserAgentHeaderValue = http.UserAgentHeaderValue
// ErrInternalError is the error returned by the router when something went wrong
// Deprecated: ErrInternalError is deprecated
ErrInternalError = http.ErrInternalError
)
// InitHTTPDefaultTransport ensures the default HTTP transport is configured just once per execution
// Deprecated: InitHTTPDefaultTransport is deprecated
var InitHTTPDefaultTransport = http.InitHTTPDefaultTransport
// RunServer runs a http.Server with the given handler and configuration
// Deprecated: RunServer is deprecated
var RunServer = http.RunServer