-
Notifications
You must be signed in to change notification settings - Fork 48
/
router.go
82 lines (74 loc) · 2.39 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
71
72
73
74
75
76
77
78
79
80
81
82
/*
Router module.
A set of functions to access the routing properties of the request.
*/
package router
import (
"github.com/Kong/go-pdk/bridge"
"github.com/Kong/go-pdk/entities"
"github.com/Kong/go-pdk/server/kong_plugin_protocol"
)
// Holds this module's functions. Accessible as `kong.Router`
type Router struct {
bridge.PdkBridge
}
// kong.Router.GetRoute() returns the current route entity.
// The request was matched against this route.
func (c Router) GetRoute() (route entities.Route, err error) {
out := new(kong_plugin_protocol.Route)
err = c.Ask(`kong.router.get_route`, nil, out)
if err != nil {
return
}
serviceId := ""
if out.Service != nil {
serviceId = out.Service.Id
}
route = entities.Route{
Id: out.Id,
CreatedAt: int(out.CreatedAt),
UpdatedAt: int(out.UpdatedAt),
Name: out.Name,
Protocols: out.Protocols,
Methods: out.Methods,
Hosts: out.Hosts,
Paths: out.Paths,
Headers: out.Headers,
HTTPSRedirectStatusCode: int(out.HttpsRedirectStatusCode),
RegexPriority: int(out.RegexPriority),
StripPath: out.StripPath,
PreserveHost: out.PreserveHost,
SNIs: out.Snis,
Sources: out.Sources,
Destinations: out.Destinations,
Tags: out.Tags,
Service: entities.ServiceKey{Id: serviceId},
}
return
}
// // kong.Router.GetService() returns the current service entity.
// // The request will be targetted to this upstream service.
func (c Router) GetService() (service entities.Service, err error) {
out := new(kong_plugin_protocol.Service)
err = c.Ask(`kong.router.get_service`, nil, out)
if err != nil {
return
}
service = entities.Service{
Id: out.Id,
CreatedAt: int(out.CreatedAt),
UpdatedAt: int(out.UpdatedAt),
Name: out.Name,
Retries: int(out.Retries),
Protocol: out.Protocol,
Host: out.Host,
Port: int(out.Port),
Path: out.Path,
ConnectTimeout: int(out.ConnectTimeout),
WriteTimeout: int(out.WriteTimeout),
ReadTimeout: int(out.ReadTimeout),
Tags: out.Tags,
// ClientCertificate: entities.CertificateKey{Id: out.ClientCertificate.Id},
}
return
}