Documentation
¶
Overview ¶
Package semaphore implements the Semaphore HTTP handlers of the relay proxy.
Index ¶
- Constants
- Variables
- func BodyOpts(operation *huma.Operation, readTimeout time.Duration)
- type AllFlags
- type CollectEvalData
- type CollectEvalDataInput
- type CollectEvalDataOutput
- type FlagChangeAPICtrl
- type FlagChangeInput
- type FlagChangeOutput
- type FlagChangeResponse
- type FlagConfigurationAPICtrl
- type FlagConfigurationError
- type FlagConfigurationInput
- type FlagConfigurationOutput
- type FlagConfigurationRequest
- type FlagConfigurationResponse
- type FlagEval
- type FlagValidationError
- type FlagValidationResponse
- type ForceFlagsRefresh
- type Health
- type HealthOutput
- type Info
- type InfoOutput
- type RawHandler
- type Request
- type RetrieverRefreshInput
- type RetrieverRefreshOutput
- type RetrieverRefreshResponse
- type SSEFlagChange
- type ValidateFlags
- type ValidateFlagsLimits
- type WSFlagChange
Constants ¶
const ( // DefaultMaxJSONBodySize is the default maximum size of a JSON body (1 MiB). DefaultMaxJSONBodySize int64 = 1 << 20 // DefaultMaxYAMLBodySize is the default maximum size of a YAML body (64 KiB). DefaultMaxYAMLBodySize int64 = 64 << 10 // DefaultMaxTOMLBodySize is the default maximum size of a TOML body (64 KiB). DefaultMaxTOMLBodySize int64 = 64 << 10 )
Variables ¶
var ErrNoFlagChange = errors.New("the flag set keeps no hashes of its flags")
ErrNoFlagChange is the failure of a flag set that keeps no hashes of its flags: the endpoint never computes them.
Functions ¶
func BodyOpts ¶ added in v0.2.0
BodyOpts configures an operation that reads its own body: huma reads the bytes (the handler decodes them, so the error bodies stay the ones of the relay proxy). The body has no size limit, as before, but the read is bound by readTimeout (the read timeout of the server, which also bound it before): a slow or stalled upload ends.
A readTimeout of zero or less means no bound: it is not the default (the server uses 30 seconds), an operator who disabled the read timeout of the server asked for it.
Types ¶
type AllFlags ¶ added in v0.2.0
type AllFlags struct {
// contains filtered or unexported fields
}
AllFlags is the controller for the /v1/allflags endpoint.
func NewAllFlags ¶
func NewAllFlags(flagsetManager service.FlagSetResolver, metrics *metric.Metrics) *AllFlags
NewAllFlags initializes the controller for the /v1/allflags endpoint.
type CollectEvalData ¶ added in v0.2.0
type CollectEvalData struct {
// contains filtered or unexported fields
}
CollectEvalData is the controller of the endpoint that collects the events of the providers.
func NewCollectEvalData ¶
func NewCollectEvalData( flagsetManager service.FlagSetResolver, metrics *metric.Metrics, ) *CollectEvalData
NewCollectEvalData initialize the controller for the /data/collector endpoint.
func (*CollectEvalData) Handle ¶ added in v0.2.0
func (h *CollectEvalData) Handle(ctx context.Context, input *CollectEvalDataInput) (*CollectEvalDataOutput, error)
Handle is the entry point for the data/collector endpoint.
type CollectEvalDataInput ¶ added in v0.2.0
type CollectEvalDataInput struct {
Request
// RawBody is the JSON document of a model.CollectEvalDataRequest, the handler decodes it.
RawBody []byte `contentType:"application/json"`
}
CollectEvalDataInput is the request of the data collector endpoint.
type CollectEvalDataOutput ¶ added in v0.2.0
type CollectEvalDataOutput struct {
Body model.CollectEvalDataResponse
}
CollectEvalDataOutput is the response of the data collector endpoint.
type FlagChangeAPICtrl ¶
type FlagChangeAPICtrl struct {
// contains filtered or unexported fields
}
FlagChangeAPICtrl is the controller of the endpoint to poll to know if the flags changed.
func NewAPIFlagChange ¶
func NewAPIFlagChange(flagsetManager service.FlagSetResolver, metrics *metric.Metrics) *FlagChangeAPICtrl
NewAPIFlagChange is the constructor of the controller of the flag change endpoint.
func (*FlagChangeAPICtrl) Handle ¶ added in v0.2.0
func (h *FlagChangeAPICtrl) Handle(ctx context.Context, in *FlagChangeInput) (*FlagChangeOutput, error)
Handle is the endpoint to poll if you want to know if there is a configuration change in the flags.
type FlagChangeInput ¶ added in v0.2.0
type FlagChangeInput struct {
Request
IfNoneMatch string `doc:"The request will be processed only if ETag doesn't match." header:"If-None-Match"`
}
FlagChangeInput is the request of the flag change endpoint.
type FlagChangeOutput ¶ added in v0.2.0
type FlagChangeOutput struct {
Body FlagChangeResponse
Status int
}
FlagChangeOutput is the response of the flag change endpoint.
type FlagChangeResponse ¶
FlagChangeResponse is the response of the flag change endpoint.
type FlagConfigurationAPICtrl ¶
type FlagConfigurationAPICtrl struct {
// contains filtered or unexported fields
}
FlagConfigurationAPICtrl serves the flag configuration API of the relay proxy.
func NewAPIFlagConfiguration ¶
func NewAPIFlagConfiguration( flagsetManager service.FlagSetResolver, metrics *metric.Metrics, ) *FlagConfigurationAPICtrl
NewAPIFlagConfiguration returns the controller that serves the flag configuration API.
func (*FlagConfigurationAPICtrl) Handle ¶ added in v0.2.0
func (h *FlagConfigurationAPICtrl) Handle( ctx context.Context, input *FlagConfigurationInput, ) (*FlagConfigurationOutput, error)
Handle is the endpoint to poll if you want to get the configuration of the flags. A request that can not be served is answered with the FlagConfigurationResponse that describes the error.
type FlagConfigurationError ¶
type FlagConfigurationError = string
FlagConfigurationError is the error code returned by the flag configuration API.
const ( // FlagConfigErrorInvalidRequest is the error code of a request that cannot be parsed. FlagConfigErrorInvalidRequest FlagConfigurationError = "INVALID_REQUEST" // FlagConfigErrorRetrievingFlags is the error code returned when the flags cannot be retrieved. FlagConfigErrorRetrievingFlags FlagConfigurationError = "RETRIEVING_FLAGS_ERROR" )
type FlagConfigurationInput ¶ added in v0.2.0
type FlagConfigurationInput struct {
Request
IfNoneMatch string `doc:"The request will be processed only if ETag doesn't match." header:"If-None-Match"`
// RawBody is the JSON document of a FlagConfigurationRequest, the handler decodes it.
RawBody []byte `contentType:"application/json"`
}
FlagConfigurationInput is the request of the flag configuration endpoint.
type FlagConfigurationOutput ¶ added in v0.2.0
type FlagConfigurationOutput struct {
LastModified string `header:"Last-Modified"`
Body FlagConfigurationResponse
Status int
}
FlagConfigurationOutput is the response of the flag configuration endpoint.
type FlagConfigurationRequest ¶
type FlagConfigurationRequest struct {
Flags []string `json:"flags" required:"false"`
}
FlagConfigurationRequest is the request body of the flag configuration API.
type FlagConfigurationResponse ¶
type FlagConfigurationResponse struct {
Flags map[string]flagdef.Flag `json:"flags,omitempty"`
EvaluationContextEnrichment map[string]any `json:"evaluationContextEnrichment,omitempty"`
ErrorCode string `json:"errorCode,omitempty"`
ErrorDetails string `json:"errorDetails,omitempty"`
}
FlagConfigurationResponse is the response body of the flag configuration API.
func (FlagConfigurationResponse) MarshalJSON ¶ added in v0.2.0
func (r FlagConfigurationResponse) MarshalJSON() ([]byte, error)
MarshalJSON encodes an answer without error with its flags member, empty when there is no flag: a provider (the Java one) takes an answer with no flag map for a failed refresh. An error answer has no flags.
type FlagEval ¶ added in v0.2.0
type FlagEval struct {
// contains filtered or unexported fields
}
FlagEval is the controller for the /v1/feature/{flagKey}/eval endpoint.
func NewFlagEval ¶
func NewFlagEval(flagsetMngr service.FlagSetResolver, metrics *metric.Metrics) *FlagEval
NewFlagEval initializes the controller for the /v1/feature/{flagKey}/eval endpoint.
type FlagValidationError ¶
type FlagValidationError struct {
Flag string `example:"my-flag" json:"flag"`
Message string `example:"missing default rule" json:"message"`
}
FlagValidationError is the validation error of a single flag.
type FlagValidationResponse ¶
type FlagValidationResponse struct {
Version string `example:"v1.0.0" json:"version"`
Errors []FlagValidationError `json:"errors"`
Valid bool `json:"valid"`
}
FlagValidationResponse is the response of the validate flags endpoint.
type ForceFlagsRefresh ¶ added in v0.2.0
type ForceFlagsRefresh struct {
// contains filtered or unexported fields
}
ForceFlagsRefresh is the controller of the endpoint that forces the refresh of the flags in the cache.
func NewForceFlagsRefresh ¶
func NewForceFlagsRefresh(flagsetManager service.FlagSetResolver, metrics *metric.Metrics) *ForceFlagsRefresh
NewForceFlagsRefresh initialize the controller for the refresh endpoint.
func (*ForceFlagsRefresh) Handle ¶ added in v0.2.0
func (h *ForceFlagsRefresh) Handle(ctx context.Context, input *RetrieverRefreshInput) (*RetrieverRefreshOutput, error)
Handle forces the refresh of the flags in the cache: it triggers the retrievers to get the latest version of the flags. It is used when you know explicitly that a flag has changed, and you want to trigger the collection of the new version.
type Health ¶ added in v0.2.0
type Health struct {
// contains filtered or unexported fields
}
Health is the controller of the health endpoint.
func NewHealth ¶
func NewHealth(monitoring service.Monitoring) *Health
NewHealth is a constructor to create a new controller for the health method.
type HealthOutput ¶ added in v0.2.0
type HealthOutput struct {
Body model.HealthResponse
}
HealthOutput is the response of the health endpoint.
type Info ¶ added in v0.2.0
type Info struct {
// contains filtered or unexported fields
}
Info is the controller of the info endpoint.
func NewInfo ¶
func NewInfo(monitoring service.Monitoring) *Info
NewInfo is the constructor of the controller of the info endpoint.
type InfoOutput ¶ added in v0.2.0
type InfoOutput struct {
Body model.InfoResponse
}
InfoOutput is the response of the info endpoint.
type RawHandler ¶ added in v0.2.0
type RawHandler interface {
Handler(w http.ResponseWriter, r *http.Request) error
}
RawHandler is the handler of an endpoint that is served without huma: it reads the request and writes the response itself, and returns the error to send when it did not write the response.
type Request ¶ added in v0.2.0
type Request struct {
// contains filtered or unexported fields
}
Request holds what the typed handlers read from the request besides their parameters: the API key and the content type of the body. huma fills it (it is not part of the description of the API).
func NewRequest ¶ added in v0.2.0
NewRequest returns the Request of a request with the API key and the content type.
func (*Request) ContentType ¶ added in v0.2.0
ContentType returns the content type of the body of the request.
type RetrieverRefreshInput ¶ added in v0.2.0
type RetrieverRefreshInput struct {
Request
}
RetrieverRefreshInput is the request of the refresh endpoint.
type RetrieverRefreshOutput ¶ added in v0.2.0
type RetrieverRefreshOutput struct {
Body RetrieverRefreshResponse
}
RetrieverRefreshOutput is the response of the refresh endpoint.
type RetrieverRefreshResponse ¶ added in v0.2.0
type RetrieverRefreshResponse struct {
Applied *bool `json:"applied,omitempty"`
Result string `json:"result,omitempty"`
Reason string `json:"reason,omitempty"`
Rejection string `json:"rejection,omitempty"`
Generation uint64 `json:"generation,omitempty"`
AppliedGeneration uint64 `json:"appliedGeneration,omitempty"`
Refreshed bool `json:"refreshed"`
Changed bool `json:"changed,omitempty"`
}
RetrieverRefreshResponse is the response of the refresh endpoint.
type SSEFlagChange ¶ added in v0.2.0
type SSEFlagChange struct {
// contains filtered or unexported fields
}
SSEFlagChange is the controller for the SSE flag change endpoint.
func NewSSEFlagChange ¶
func NewSSEFlagChange( sseService stream.SSEService, flagsetManager service.FlagSetResolver, ) *SSEFlagChange
NewSSEFlagChange is the constructor to create a new controller to handle SSE requests to be notified about flag changes.
func (*SSEFlagChange) Handler ¶ added in v0.2.0
func (h *SSEFlagChange) Handler(w http.ResponseWriter, r *http.Request) error
Handler is the entry point for the SSE endpoint to be notified of flag changes.
type ValidateFlags ¶ added in v0.2.0
type ValidateFlags struct {
// contains filtered or unexported fields
}
ValidateFlags is the controller for the /admin/v1/flags/validate endpoint.
func NewValidateFlags ¶
func NewValidateFlags( version string, metrics *metric.Metrics, limits ValidateFlagsLimits, ) *ValidateFlags
NewValidateFlags initializes the controller for the /admin/v1/flags/validate endpoint. The unset (zero) limits are replaced by their default.
func (*ValidateFlags) Handler ¶ added in v0.2.0
func (h *ValidateFlags) Handler(w http.ResponseWriter, r *http.Request) error
Handler validates a flag file without loading it in the relay proxy.
type ValidateFlagsLimits ¶ added in v0.2.0
type ValidateFlagsLimits struct {
// MaxJSONBodySize is the maximum size of a JSON body.
MaxJSONBodySize int64
// MaxYAMLBodySize is the maximum size of a YAML body.
MaxYAMLBodySize int64
// MaxTOMLBodySize is the maximum size of a TOML body.
MaxTOMLBodySize int64
}
ValidateFlagsLimits are the maximum sizes in bytes of the body of the validate flags endpoint, by format. A zero limit means that the default is used, the limits are not negative.
func (ValidateFlagsLimits) WithDefaults ¶ added in v0.2.0
func (l ValidateFlagsLimits) WithDefaults() ValidateFlagsLimits
WithDefaults returns a copy where the unset (zero) limits are replaced by their default.
type WSFlagChange ¶
type WSFlagChange struct {
// contains filtered or unexported fields
}
WSFlagChange is the implementation of the controller.
func NewWsFlagChange ¶
func NewWsFlagChange( websocketService stream.WebsocketService, flagsetManager service.FlagSetResolver, ) *WSFlagChange
NewWsFlagChange is the constructor to create a new controller to handle websocket request to be notified about flag changes.
func (*WSFlagChange) Handler ¶
func (f *WSFlagChange) Handler(w http.ResponseWriter, r *http.Request) error
Handler is the entry point for the websocket endpoint to get notified when a flag has been edited.
func (*WSFlagChange) LegacyHandler ¶
func (f *WSFlagChange) LegacyHandler(w http.ResponseWriter, r *http.Request) error
LegacyHandler is the entry point for the websocket endpoint to get notified when a flag has been edited.