-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathroute_descriptor.go
More file actions
40 lines (33 loc) · 911 Bytes
/
route_descriptor.go
File metadata and controls
40 lines (33 loc) · 911 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
package velaros
import (
"encoding/json"
)
// RouteDescriptor describes a public route registered with PublicBind. Route descriptors
// are used by API gateway frameworks for service discovery and routing. Access them via
// Router.RouteDescriptors().
type RouteDescriptor struct {
Pattern *Pattern
}
// MarshalJSON returns the JSON representation of the route descriptor.
func (r *RouteDescriptor) MarshalJSON() ([]byte, error) {
return json.Marshal(struct {
Pattern string
}{
Pattern: r.Pattern.String(),
})
}
// UnmarshalJSON parses the JSON representation of the route descriptor.
func (r *RouteDescriptor) UnmarshalJSON(data []byte) error {
fromJSONStruct := struct {
Pattern string
}{}
if err := json.Unmarshal(data, &fromJSONStruct); err != nil {
return err
}
pattern, err := NewPattern(fromJSONStruct.Pattern)
if err != nil {
return err
}
r.Pattern = pattern
return nil
}