Atlas › Test

ExampleRoute_Deserialize

Exact test identity: go.temporal.io/server/common/routing/ExampleRoute_Deserialize

Package
go.temporal.io/server/common/routing
Suite / test hierarchy
ExampleRoute_Deserialize
Test
ExampleRoute_Deserialize
Introduced at
route.go ×3 Frontier kind: Joint frontier
Covered ranges
11
Covered lines
35
Covered files
1

Co-introduced tests

1 other test enter at the same concept.

Covered source

Expand a file to inspect source; the > gutter marks covered lines.

go.temporal.io/server/common/routing/route.go 35 covered LOC · 11 ranges

Open complete file

36
37 // NewRoute returns a new [Route] instance with the given components.
38 > func NewRoute[T any](components ...Component[T]) Route[T] { route.go
39 > return Route[T]{components: components}
40 > }
41
42 // RouteBuilder is a builder for the [Route] interface.
46
47 // NewBuilder creates a new [RouteBuilder] instance, which can be used to define a new [Route] via a fluent API.
48 > func NewBuilder[T any]() *RouteBuilder[T] { route.go
49 > return &RouteBuilder[T]{}
50 > }
51
52 // With adds a series of [Component] instances to the [Route].
53 > func (r *RouteBuilder[T]) With(c ...Component[T]) *RouteBuilder[T] { route.go
54 > r.components = append(r.components, c...)
55 > return r
56 > }
57
58 // Constant adds a [Constant] component to the [Route].
59 > func (r *RouteBuilder[T]) Constant(values ...string) *RouteBuilder[T] { route.go
60 > return r.With(Constant[T](values...))
61 > }
62
63 // StringVariable adds a [StringVariable] component to the [Route].
64 > func (r *RouteBuilder[T]) StringVariable(name string, getter func(*T) *string) *RouteBuilder[T] { route.go
65 > return r.With(StringVariable[T](name, getter))
66 > }
67
68 // Build returns a read-only [Route].
69 > func (r *RouteBuilder[T]) Build() Route[T] { route.go
70 > return NewRoute[T](r.components...)
71 > }
72
73 // Representation returns the [github.com/gorilla/mux] compatible string representation of the route for usage in a
101
102 // Deserialize the given vars into a new instance of the params type, T.
103 > func (r Route[T]) Deserialize(vars map[string]string) T { route.go
104 > var t T
105 > for _, c := range r.components {
106 > c.Deserialize(vars, &t)
107 > }
108 > return t
109 }
110
111 // Constant returns a [Component] that represents a series of constant HTTP path components in a Route.
112 // They will be joined via strings when used to construct a path or path representation.
113 > func Constant[T any](values ...string) constant[T] { route.go
114 > return values
115 > }
116
117 type constant[T any] []string
125 }
126
127 > func (s constant[T]) Deserialize(map[string]string, *T) {} route.go
128
129 // StringVariable returns a [Component] that represents a string variable in a Route.
130 > func StringVariable[T any](name string, getter func(*T) *string) stringVariable[T] { route.go
131 > return stringVariable[T]{name, getter}
132 > }
133
134 type stringVariable[T any] struct {
145 }
146
147 > func (s stringVariable[T]) Deserialize(vars map[string]string, t *T) { route.go
148 > *s.getter(t) = vars[s.name]
149 > }