2019-01-08 00:37:16 +00:00
|
|
|
package influxdb
|
2018-12-03 16:07:08 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
)
|
|
|
|
|
2018-12-07 18:25:11 +00:00
|
|
|
// ErrLabelNotFound is the error for a missing Label.
|
|
|
|
const ErrLabelNotFound = ChronografError("label not found")
|
|
|
|
|
2018-12-18 07:59:04 +00:00
|
|
|
const (
|
|
|
|
OpFindLabels = "FindLabels"
|
|
|
|
OpCreateLabel = "CreateLabel"
|
|
|
|
OpUpdateLabel = "UpdateLabel"
|
|
|
|
OpDeleteLabel = "DeleteLabel"
|
|
|
|
)
|
|
|
|
|
2018-12-03 16:07:08 +00:00
|
|
|
type LabelService interface {
|
|
|
|
// FindLabels returns a list of labels that match a filter
|
|
|
|
FindLabels(ctx context.Context, filter LabelFilter, opt ...FindOptions) ([]*Label, error)
|
|
|
|
|
|
|
|
// CreateLabel creates a new label
|
|
|
|
CreateLabel(ctx context.Context, l *Label) error
|
|
|
|
|
2018-12-18 06:30:41 +00:00
|
|
|
// UpdateLabel updates a label with a changeset.
|
|
|
|
UpdateLabel(ctx context.Context, l *Label, upd LabelUpdate) (*Label, error)
|
2018-12-17 22:13:43 +00:00
|
|
|
|
2018-12-03 16:07:08 +00:00
|
|
|
// DeleteLabel deletes a label
|
|
|
|
DeleteLabel(ctx context.Context, l Label) error
|
|
|
|
}
|
|
|
|
|
|
|
|
type Label struct {
|
2018-12-20 21:41:20 +00:00
|
|
|
ResourceID ID `json:"resourceID"`
|
2018-12-20 20:27:27 +00:00
|
|
|
Name string `json:"name"`
|
|
|
|
Properties map[string]string `json:"properties"`
|
2018-12-03 16:07:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Validate returns an error if the label is invalid.
|
|
|
|
func (l *Label) Validate() error {
|
|
|
|
if !l.ResourceID.Valid() {
|
2018-12-18 16:36:18 +00:00
|
|
|
return &Error{
|
|
|
|
Code: EInvalid,
|
|
|
|
Msg: "resourceID is required",
|
|
|
|
}
|
2018-12-03 16:07:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if l.Name == "" {
|
2018-12-18 16:36:18 +00:00
|
|
|
return &Error{
|
|
|
|
Code: EInvalid,
|
|
|
|
Msg: "label name is required",
|
|
|
|
}
|
2018-12-03 16:07:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-12-18 06:30:41 +00:00
|
|
|
// LabelUpdate represents a changeset for a label.
|
|
|
|
// Only fields which are set are updated.
|
|
|
|
type LabelUpdate struct {
|
2018-12-20 21:52:35 +00:00
|
|
|
Properties map[string]string `json:"properties,omitempty"`
|
2018-12-18 16:56:14 +00:00
|
|
|
}
|
|
|
|
|
2018-12-03 16:07:08 +00:00
|
|
|
type LabelFilter struct {
|
|
|
|
ResourceID ID
|
|
|
|
Name string
|
|
|
|
}
|