Atlas › Test
Path
Exact test identity: go.temporal.io/server/common/routing/TestNewRoute/Path
- Package
go.temporal.io/server/common/routing
- Suite / test hierarchy
TestNewRoute/Path
- Test
Path
- Introduced at
- route.go ×1 Frontier kind: Joint frontier
- Covered ranges
- 13
- Covered lines
- 43
- 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 43 covered LOC · 13 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
75
// they're present in the components. We do this because it's easier to add a slash depending on the context than to
76
// remove it.
77
>
func (r Route[T]) Representation() string {
route.go
78
>
return r.serialize(func(c Component[T]) string {
79
>
return c.Representation()
80
>
})
81
}
82
89
}
90
91
>
func (r Route[T]) serialize(f func(c Component[T]) string) string {
route.go
92
>
var sb strings.Builder
93
>
for i, c := range r.components {
94
>
if i > 0 {
95
>
sb.WriteString("/")
96
>
}
97
>
sb.WriteString(f(c))
98
}
100
}
101
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
118
119
>
func (s constant[T]) Representation() string {
route.go
120
>
return strings.Join(s, "/")
121
>
}
122
123
func (s constant[T]) Serialize(T) string {
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 {
137
}
138
139
>
func (s stringVariable[T]) Representation() string {
route.go
140
>
return "{" + s.name + "}"
141
>
}
142
143
func (s stringVariable[T]) Serialize(t T) string {