go.temporal.io/server/common/routing/route.go

149 LOC · 63 covered · 86 uncovered · 19 ranges · 17487 concepts · 9 introducers · 8723 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the filemetric_client.go ×3 · 18 introduced LOCmetric_client.go ×3workflow_task_completed_handler.go ×1 · 6 introduced LOCworkflow_task_completed_…admin_handler.go ×1 · 2 introduced LOCadmin_handler.go ×1workflow_handler.go ×1 · 4 introduced LOCworkflow_handler.go ×1workflow_handler.go ×2 · 9 introduced LOCworkflow_handler.go ×2operator_handler.go ×5 · 65 introduced LOCoperator_handler.go ×5operator_handler.go ×1 · 2 introduced LOCoperator_handler.go ×1version_rule_helpers.go ×2 · 7 introduced LOCversion_rule_helpers.go …reachability.go ×2 · 2 introduced LOCreachability.go ×2namespace_handler.go ×4 · 44 introduced LOCnamespace_handler.go ×4scavenger.go ×16 · 84 introduced LOCscavenger.go ×16workflow_handler.go ×9 · 33 introduced LOCworkflow_handler.go ×9TestGetNextTimeComputeLimitWarning · 0 introduced LOCTestGetNextTimeComputeLi…query.go ×1 · 4 introduced LOCquery.go ×1activities.go ×10 · 52 introduced LOCactivities.go ×10TestSpecIntervalPhase, TestSpecIntervalMultiple · 0 introduced LOCTestSpecIntervalPhase, T…service_grpc.pb.mock.go ×1 · 5 introduced LOCservice_grpc.pb.mock.go …scavenger.go ×8 · 43 introduced LOCscavenger.go ×8request_response.pb.go ×2 · 9 introduced LOCrequest_response.pb.go ×…TestCalendarMatch · 0 introduced LOCTestCalendarMatchworkflow_service_server_gen.go ×1 · 2 introduced LOCworkflow_service_server_…matching_service_server_gen.go ×1 · 5 introduced LOCmatching_service_server_…request_response.pb.go ×1 · 9 introduced LOCrequest_response.pb.go ×…workflow.go ×2 · 4 introduced LOCworkflow.go ×2Frontend_GetWorkflowExecutionHistoryRequest_with_execution · 0 introduced LOCFrontend_GetWorkflowExec…Frontend_StartWorkflowExecutionRequest_with_only_workflowID · 0 introduced LOCFrontend_StartWorkflowEx…matching_service_server_gen.go ×1 · 2 introduced LOCmatching_service_server_…activities.go ×1 · 26 introduced LOCactivities.go ×1workflow_tags.go ×3 · 5 introduced LOCworkflow_tags.go ×3workflow_service_server_gen.go ×1 · 5 introduced LOCworkflow_service_server_…history_service_server_gen.go ×1 · 4 introduced LOChistory_service_server_g…Test_findBuildIdsToRemove_AcceptsNilVersioningData · 0 introduced LOCTest_findBuildIdsToRemov…workflow_service_server_gen.go ×1 · 4 introduced LOCworkflow_service_server_…tags.go ×1 · 3 introduced LOCtags.go ×1data_interfaces_mock.go ×2 · 11 introduced LOCdata_interfaces_mock.go …matching_service_server_gen.go ×1 · 4 introduced LOCmatching_service_server_…scheduler.go ×1 · 5 introduced LOCscheduler.go ×1data_interfaces_mock.go ×2 · 11 introduced LOCdata_interfaces_mock.go …hybrid_logical_clock.go ×1 · 3 introduced LOChybrid_logical_clock.go …spec.go ×7 · 20 introduced LOCspec.go ×7errors.go ×1 · 3 introduced LOCerrors.go ×1namespace.go ×1 · 2 introduced LOCnamespace.go ×1calendar.go ×2 · 8 introduced LOCcalendar.go ×2task_queues.pb.go ×1 · 2 introduced LOCtask_queues.pb.go ×1task_queues.pb.go ×1 · 2 introduced LOCtask_queues.pb.go ×1TestProcessBufferEmpty · 0 introduced LOCTestProcessBufferEmptytags.go ×1 · 3 introduced LOCtags.go ×1task_queues.pb.go ×1 · 1 introduced LOCtask_queues.pb.go ×1worker_versioning.go ×1 · 3 introduced LOCworker_versioning.go ×1buffer.go ×3 · 16 introduced LOCbuffer.go ×3task_queues.pb.go ×1 · 2 introduced LOCtask_queues.pb.go ×1calendar.go ×2 · 4 introduced LOCcalendar.go ×2constants.go ×1 · 2 introduced LOCconstants.go ×1FuzzCalendar, TestGoDSTBehavior · 0 introduced LOCFuzzCalendar, TestGoDSTB…workflow.go ×3 · 15 introduced LOCworkflow.go ×3request_response.pb.go ×1 · 4 introduced LOCrequest_response.pb.go ×…worker_versioning.go ×4 · 18 introduced LOCworker_versioning.go ×4errors.go ×1 · 3 introduced LOCerrors.go ×1TestAbortReasonUpdateStateMatrix · 0 introduced LOCTestAbortReasonUpdateSta…request_response.pb.go ×2 · 20 introduced LOCrequest_response.pb.go ×…routes.go ×2 · 2 introduced LOCroutes.go ×2routes.go ×1 · 1 introduced LOCroutes.go ×1link_converter.go ×1 · 17 introduced LOClink_converter.go ×1link_converter.go ×1 · 17 introduced LOClink_converter.go ×1ExampleRoute · 0 introduced LOCExampleRouteroute.go ×1 · 4 introduced LOCroute.go ×1route.go ×3 · 10 introduced LOCroute.go ×3route.go ×3 · 10 introduced LOCroute.go ×3route.go ×2 · 8 introduced LOCroute.go ×2route.go ×6 · 19 introduced LOCroute.go ×6route.go ×1 · 3 introduced LOCroute.go ×1route.go ×1 · 3 introduced LOCroute.go ×1route.go ×1 · 3 introduced LOCroute.go ×1route.go ×1 · 3 introduced LOCroute.go ×1mixed · introduced test · go.temporal.io/server/chasm/lib/scheduler/TestUserCustomSearchAttributes/mixedmixedreserved_only · introduced test · go.temporal.io/server/chasm/lib/scheduler/TestUserCustomSearchAttributes/reserved_onlyreserved_onlyExampleRouteDispatchNexusTaskByEndpoint · introduced test · go.temporal.io/server/common/nexus/ExampleRouteDispatchNexusTaskByEndpointExampleRouteDispatchNexu…ExampleRouteDispatchNexusTaskByNamespaceAndTaskQueue · introduced test · go.temporal.io/server/common/nexus/ExampleRouteDispatchNexusTaskByNamespaceAndTaskQueueExampleRouteDispatchNexu…TestConvertLinkActivityToNexusLink · introduced test · go.temporal.io/server/common/nexus/TestConvertLinkActivityToNexusLinkTestConvertLinkActivityT…TestConvertLinkNexusOperationToNexusLink · introduced test · go.temporal.io/server/common/nexus/TestConvertLinkNexusOperationToNexusLinkTestConvertLinkNexusOper…ExampleConstant · introduced test · go.temporal.io/server/common/routing/ExampleConstantExampleConstantExampleRoute · introduced test · go.temporal.io/server/common/routing/ExampleRouteExampleRouteExampleRoute_Deserialize · introduced test · go.temporal.io/server/common/routing/ExampleRoute_DeserializeExampleRoute_DeserializeExampleRoute_Path · introduced test · go.temporal.io/server/common/routing/ExampleRoute_PathExampleRoute_PathExampleRoute_Representation · introduced test · go.temporal.io/server/common/routing/ExampleRoute_RepresentationExampleRoute_Representat…ExampleStringVariable · introduced test · go.temporal.io/server/common/routing/ExampleStringVariableExampleStringVariableGet · introduced test · go.temporal.io/server/common/routing/TestNewRoute/GetGetPath · introduced test · go.temporal.io/server/common/routing/TestNewRoute/PathPathSet · introduced test · go.temporal.io/server/common/routing/TestNewRoute/SetSetFrontend_GetWorkflowExecutionHistoryRequest_with_execution · introduced test · go.temporal.io/server/common/rpc/interceptor/logtags/TestExtract/Frontend_GetWorkflowExecutionHistoryRequest_with_executionFrontend_GetWorkflowExec…Frontend_RespondActivityTaskCompletedRequest_with_task_token · introduced test · go.temporal.io/server/common/rpc/interceptor/logtags/TestExtract/Frontend_RespondActivityTaskCompletedRequest_with_task_tokenFrontend_RespondActivity…Frontend_StartWorkflowExecutionRequest_with_only_workflowID · introduced test · go.temporal.io/server/common/rpc/interceptor/logtags/TestExtract/Frontend_StartWorkflowExecutionRequest_with_only_workflowIDFrontend_StartWorkflowEx…History_DescribeWorkflowExecutionRequest · introduced test · go.temporal.io/server/common/rpc/interceptor/logtags/TestExtract/History_DescribeWorkflowExecutionRequestHistory_DescribeWorkflow…Matching_QueryWorkflowRequest · introduced test · go.temporal.io/server/common/rpc/interceptor/logtags/TestExtract/Matching_QueryWorkflowRequestMatching_QueryWorkflowRe…Matching_RespondWorkflowTaskCompletedRequest · introduced test · go.temporal.io/server/common/rpc/interceptor/logtags/TestExtract/Matching_RespondWorkflowTaskCompletedRequestMatching_RespondWorkflow…handles_empty_versions_map · introduced test · go.temporal.io/server/common/worker_versioning/TestCleanupOldDeletedVersions/handles_empty_versions_maphandles_empty_versions_m…reserved_key_(ES_configured) · introduced test · go.temporal.io/server/service/frontend/TestAdminHandlerSuite/Test_AddSearchAttributes/reserved_key_(ES_configured)reserved_key_(ES_configu…reserved_key_(empty_index) · introduced test · go.temporal.io/server/service/frontend/TestAdminHandlerSuite/Test_AddSearchAttributes/reserved_key_(empty_index)reserved_key_(empty_inde…TestDescribeScheduleAnnotatesScheduledWorkflowWithTypes · introduced test · go.temporal.io/server/service/frontend/TestDescribeScheduleAnnotatesScheduledWorkflowWithTypesTestDescribeScheduleAnno…TestListNamespace · introduced test · go.temporal.io/server/service/frontend/TestNamespaceHandlerCommonSuite/TestListNamespaceTestListNamespacefail:_cannot_add_reserved_name_search_attribute · introduced test · go.temporal.io/server/service/frontend/TestOperatorHandlerSuite/Test_AddSearchAttributes/fail:_cannot_add_reserved_name_search_attributefail:_cannot_add_reserve…Test_DeleteNamespace · introduced test · go.temporal.io/server/service/frontend/TestOperatorHandlerSuite/Test_DeleteNamespaceTest_DeleteNamespaceTestGetSearchAttributes · introduced test · go.temporal.io/server/service/frontend/TestWorkflowHandlerSuite/TestGetSearchAttributesTestGetSearchAttributesTestShutdownWorkerWithCancellationError · introduced test · go.temporal.io/server/service/frontend/TestWorkflowHandlerSuite/TestShutdownWorkerWithCancellationErrorTestShutdownWorkerWithCa…TestRespondWorkflowTaskCompleted_StartChildWithSearchAttributes · introduced test · go.temporal.io/server/service/history/TestEngine2Suite/TestRespondWorkflowTaskCompleted_StartChildWithSearchAttributesTestRespondWorkflowTaskC…TestAbortReasonUpdateStateMatrix · introduced test · go.temporal.io/server/service/history/workflow/update/TestAbortReasonUpdateStateMatrixTestAbortReasonUpdateSta…TestCleanupRedirectRuleTombstones · introduced test · go.temporal.io/server/service/matching/TestCleanupRedirectRuleTombstonesTestCleanupRedirectRuleT…TestGetBuildIdsOfInterest · introduced test · go.temporal.io/server/service/matching/TestGetBuildIdsOfInterestTestGetBuildIdsOfInteres…Test_DeleteNamespaceWorkflow_ByNameAndID · introduced test · go.temporal.io/server/service/worker/deletenamespace/Test_DeleteNamespaceWorkflow_ByNameAndIDTest_DeleteNamespaceWork…Test_GenerateDeletedNamespaceNameActivity · introduced test · go.temporal.io/server/service/worker/deletenamespace/Test_GenerateDeletedNamespaceNameActivityTest_GenerateDeletedName…TestSeedReplicationQueueWithUserDataEntries_Heartbeats · introduced test · go.temporal.io/server/service/worker/migration/TestSeedReplicationQueueWithUserDataEntries_HeartbeatsTestSeedReplicationQueue…Test_ScavengeBuildIds_Heartbeats · introduced test · go.temporal.io/server/service/worker/scanner/build_ids/Test_ScavengeBuildIds_HeartbeatsTest_ScavengeBuildIds_He…Test_findBuildIdsToRemove_AcceptsNilVersioningData · introduced test · go.temporal.io/server/service/worker/scanner/build_ids/Test_findBuildIdsToRemove_AcceptsNilVersioningDataTest_findBuildIdsToRemov…FuzzCalendar · introduced test · go.temporal.io/server/service/worker/scheduler/FuzzCalendarFuzzCalendarTestCalendarMatch · introduced test · go.temporal.io/server/service/worker/scheduler/TestCalendar/TestCalendarMatchTestCalendarMatchTestDaysInMonth · introduced test · go.temporal.io/server/service/worker/scheduler/TestCalendar/TestDaysInMonthTestDaysInMonthTestGoDSTBehavior · introduced test · go.temporal.io/server/service/worker/scheduler/TestCalendar/TestGoDSTBehaviorTestGoDSTBehaviorTestProcessBufferEmpty · introduced test · go.temporal.io/server/service/worker/scheduler/TestProcessBuffer/TestProcessBufferEmptyTestProcessBufferEmptyTestGetNextTimeComputeLimitWarning · introduced test · go.temporal.io/server/service/worker/scheduler/TestSpec/TestGetNextTimeComputeLimitWarningTestGetNextTimeComputeLi…TestSpecIntervalMultiple · introduced test · go.temporal.io/server/service/worker/scheduler/TestSpec/TestSpecIntervalMultipleTestSpecIntervalMultipleTestSpecIntervalPhase · introduced test · go.temporal.io/server/service/worker/scheduler/TestSpec/TestSpecIntervalPhaseTestSpecIntervalPhaseinvalid_filter_system_search_attribute · introduced test · go.temporal.io/server/service/worker/scheduler/TestValidateVisibilityQuery/invalid_filter_system_search_attributeinvalid_filter_system_se…TestNewServerWithJSONEncoding · introduced test · go.temporal.io/server/temporal/TestNewServerWithJSONEncodingTestNewServerWithJSONEnc…Focused file · go.temporal.io/server/common/routing/route.go · 149 LOCrouting/route.go

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 // Package routing provides utilities to define a number of [Route] instances, which can be...
2 //
3 // 1. Used by servers to...
4 //
5 // 1.a. Register with [github.com/gorilla/mux.Router] instances via the [Route.Representation] method.
6 //
7 // 1.b. Deserialize HTTP path variables into a struct with the [Route.Deserialize] method.
8 //
9 // 2. Used by clients to construct HTTP paths for requests by calling the [Route.Path] method.
10 package routing
11
12 import (
13 "net/url"
14 "strings"
15 )
16
17 // Route represents a series of HTTP path components.
18 type Route[T any] struct {
19 components []Component[T]
20 }
21
22 // Component represents a single HTTP path component, either a constant slug or a variable parameter.
23 type Component[T any] interface {
24 // Representation is the string representation of the component for usage in a path definition, e.g. "v1" for a
25 // constant slug or "{namespace}" for a variable. This should be compatible with the format specified in
26 // the [github.com/gorilla/mux] package.
27 Representation() string
28 // Serialize returns the actual value of the slug when used in an HTTP path, e.g. "v1" for a constant slug or
29 // "test-namespace" for a variable.
30 Serialize(params T) string
31 // Deserialize mutates the given params object with the value of the component when parsing an HTTP path, e.g.
32 // setting the value of a variable to "test-namespace". If the component is a constant slug, this method should
33 // be a no-op.
34 Deserialize(vars map[string]string, t *T)
35 }
36
37 // NewRoute returns a new [Route] instance with the given components.
38 > func NewRoute[T any](components ...Component[T]) Route[T] { route.go ×6
39 > return Route[T]{components: components}
40 > }
41
42 // RouteBuilder is a builder for the [Route] interface.
43 type RouteBuilder[T any] struct {
44 components []Component[T]
45 }
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 ×6
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 ×6
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 ×6
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 ×6
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 ×6
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
74 // path definition. It does not add a leading or trailing slash to the representation, but it won't remove them if
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 ×1
78 > return r.serialize(func(c Component[T]) string {
79 > return c.Representation()
80 > })
81 }
82
83 // Path returns the serialized path of the route with the given params. There will be no leading or trailing slashes,
84 // similar to the behavior of the [Route.Representation] method.
85 > func (r Route[T]) Path(t T) string { route.go ×3
86 > return r.serialize(func(c Component[T]) string {
87 > return c.Serialize(t)
88 > })
89 }
90
91 > func (r Route[T]) serialize(f func(c Component[T]) string) string { route.go ×2
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 }
99 > return sb.String() route.go ×2
100 }
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 ×3
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 ×1
114 > return values
115 > }
116
117 type constant[T any] []string
118
119 > func (s constant[T]) Representation() string { route.go ×1
120 > return strings.Join(s, "/")
121 > }
122
123 > func (s constant[T]) Serialize(T) string { route.go ×3
124 > return strings.Join(s, "/")
125 > }
126
127 > func (s constant[T]) Deserialize(map[string]string, *T) {} route.go ×3
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 ×1
131 > return stringVariable[T]{name, getter}
132 > }
133
134 type stringVariable[T any] struct {
135 name string
136 getter func(*T) *string
137 }
138
139 > func (s stringVariable[T]) Representation() string { route.go ×1
140 > return "{" + s.name + "}"
141 > }
142
143 > func (s stringVariable[T]) Serialize(t T) string { route.go ×3
144 > return url.PathEscape(*s.getter(&t))
145 > }
146
147 > func (s stringVariable[T]) Deserialize(vars map[string]string, t *T) { route.go ×3
148 > *s.getter(t) = vars[s.name]
149 > }