Documentation ¶
Index ¶
- Constants
- func RespondProblem(problem Problem, w http.ResponseWriter)
- type GenericUserError
- type ManagedModel
- type Meter
- type MeterAggregation
- type MeterNotFoundError
- type MeterOptions
- type MeterQueryRow
- type NamespaceNotFoundError
- type NamespacedID
- type NamespacedModel
- type Problem
- type ProblemType
- type StatusProblem
- type SubjectKey
- type WindowSize
Constants ¶
const ProblemContentType = "application/problem+json"
ProblemContentType is the default content type for a Problem response
const ( // ProblemTypeDefault is the default problem type. ProblemTypeDefault = ProblemType("about:blank") )
Variables ¶
This section is empty.
Functions ¶
func RespondProblem ¶
func RespondProblem(problem Problem, w http.ResponseWriter)
Respond will render the problem as JSON to the provided ResponseWriter.
Types ¶
type GenericUserError ¶
type GenericUserError struct {
Message string
}
TODO: this should be picked up in a general server error handler
func (*GenericUserError) Error ¶
func (e *GenericUserError) Error() string
type ManagedModel ¶
type Meter ¶
type Meter struct { // We don't accept namespace via config, it's set by the `namespace.default`.` Namespace string `json:"-" yaml:"-"` ID string `json:"id,omitempty" yaml:"id,omitempty"` Slug string `json:"slug" yaml:"slug"` Description string `json:"description,omitempty" yaml:"description,omitempty"` Aggregation MeterAggregation `json:"aggregation" yaml:"aggregation"` EventType string `json:"eventType" yaml:"eventType"` ValueProperty string `json:"valueProperty,omitempty" yaml:"valueProperty,omitempty"` GroupBy map[string]string `json:"groupBy,omitempty" yaml:"groupBy,omitempty"` WindowSize WindowSize `json:"windowSize,omitempty" yaml:"windowSize,omitempty"` }
func NewMeter ¶
func NewMeter( slug string, aggregatation MeterAggregation, eventType string, valueProperty string, options *MeterOptions, ) (*Meter, error)
func (*Meter) SupportsWindowSize ¶
func (m *Meter) SupportsWindowSize(w *WindowSize) error
type MeterAggregation ¶
type MeterAggregation string
const ( MeterAggregationSum MeterAggregation = "SUM" MeterAggregationCount MeterAggregation = "COUNT" MeterAggregationAvg MeterAggregation = "AVG" MeterAggregationMin MeterAggregation = "MIN" MeterAggregationMax MeterAggregation = "MAX" MeterAggregationUniqueCount MeterAggregation = "UNIQUE_COUNT" )
func (MeterAggregation) IsValid ¶
func (MeterAggregation) IsValid(input string) bool
func (MeterAggregation) Values ¶
func (MeterAggregation) Values() (kinds []string)
Values provides list valid values for Enum
type MeterNotFoundError ¶
type MeterNotFoundError struct {
MeterSlug string
}
func (*MeterNotFoundError) Error ¶
func (e *MeterNotFoundError) Error() string
type MeterOptions ¶
type MeterOptions struct { ID string Description string GroupBy map[string]string WindowSize *WindowSize }
type MeterQueryRow ¶
type MeterQueryRow struct { Value float64 `json:"value"` WindowStart time.Time `json:"windowStart"` WindowEnd time.Time `json:"windowEnd"` Subject *string `json:"subject"` GroupBy map[string]*string `json:"groupBy"` }
MeterQueryRow returns a single row from the meter dataset.
func (*MeterQueryRow) Render ¶
func (m *MeterQueryRow) Render(_ http.ResponseWriter, _ *http.Request) error
Render implements the chi renderer interface.
type NamespaceNotFoundError ¶
type NamespaceNotFoundError struct {
Namespace string
}
func (*NamespaceNotFoundError) Error ¶
func (e *NamespaceNotFoundError) Error() string
type NamespacedID ¶
type NamespacedModel ¶
type NamespacedModel struct {
Namespace string `json:"-" yaml:"-"`
}
type Problem ¶
type Problem interface { Respond(w http.ResponseWriter) Error() string ProblemType() ProblemType ProblemTitle() string ProblemStatus() int }
Problem is the RFC 7807 response body.
type ProblemType ¶
type ProblemType string
ProblemType contains a URI that identifies the problem type. This URI will, ideally, contain human-readable documentation for the problem when de-referenced.
type StatusProblem ¶
type StatusProblem struct { Err error `json:"-"` // low-level runtime error // Type is a URI reference that identifies the problem type. Type ProblemType `json:"type"` // Title is a short, human-readable summary of the problem type. Title string `json:"title"` // Status is the HTTP status code generated by the origin server for this occurrence of the problem. Status int `json:"status"` // Detail is a human-readable explanation specific to this occurrence of the problem. Detail string `json:"detail,omitempty"` // Instance is a URI reference that identifies the specific occurrence of the problem. Instance string `json:"instance,omitempty"` // Extension fields are allowed by spec, see https://datatracker.ietf.org/doc/html/rfc7807#section-3.2 Extensions map[string]interface{} `json:"extensions,omitempty"` }
StatusProblem is the RFC 7807 response body without additional fields.
func NewStatusProblem ¶
func NewStatusProblem(ctx context.Context, err error, status int) *StatusProblem
NewStatusProblem will generate a problem for the provided HTTP status code. The Problem's Status field will be set to match the status argument, and the Title will be set to the default Go status text for that code.
func (*StatusProblem) Error ¶
func (p *StatusProblem) Error() string
func (*StatusProblem) ProblemStatus ¶
func (p *StatusProblem) ProblemStatus() int
func (*StatusProblem) ProblemTitle ¶
func (p *StatusProblem) ProblemTitle() string
func (*StatusProblem) ProblemType ¶
func (p *StatusProblem) ProblemType() ProblemType
func (*StatusProblem) RawError ¶
func (p *StatusProblem) RawError() error
func (*StatusProblem) Respond ¶
func (p *StatusProblem) Respond(w http.ResponseWriter)
Respond will render the problem as JSON to the provided ResponseWriter.
type SubjectKey ¶
type SubjectKey string
type WindowSize ¶
type WindowSize string
const ( WindowSizeMinute WindowSize = "MINUTE" WindowSizeHour WindowSize = "HOUR" WindowSizeDay WindowSize = "DAY" )
func WindowSizeFromDuration ¶
func WindowSizeFromDuration(duration time.Duration) (WindowSize, error)
func (WindowSize) Duration ¶
func (w WindowSize) Duration() time.Duration
Duration returns the duration of the window size
func (WindowSize) Values ¶
func (WindowSize) Values() (kinds []string)
Values provides list valid values for Enum