feature

package
v1.0.0-beta.206 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 4, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FeatureEventSubsystem   metadata.EventSubsystem = "feature"
	FeatureCreateEventName  metadata.EventName      = "feature.created"
	FeatureUpdateEventName  metadata.EventName      = "feature.updated"
	FeatureArchiveEventName metadata.EventName      = "feature.archived"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateFeatureInputs

type CreateFeatureInputs struct {
	Name                string              `json:"name"`
	Key                 string              `json:"key"`
	Namespace           string              `json:"namespace"`
	MeterSlug           *string             `json:"meterSlug"`
	MeterGroupByFilters MeterGroupByFilters `json:"meterGroupByFilters"`
	Metadata            map[string]string   `json:"metadata"`
}

type Feature

type Feature struct {
	Namespace string `json:"namespace"`
	ID        string `json:"id,omitempty"`

	// Name The name of the feature.
	Name string `json:"name"`
	// Key The unique key of the feature.
	Key string `json:"key"`

	// MeterSlug The meter that the feature is associated with and decreases grants by usage.
	MeterSlug *string `json:"meterSlug,omitempty"`

	// MeterGroupByFilters Optional meter group by filters. Useful if the meter scope is broader than what feature tracks.
	MeterGroupByFilters MeterGroupByFilters `json:"meterGroupByFilters,omitempty"`

	// Metadata Additional metadata.
	Metadata map[string]string `json:"metadata,omitempty"`

	// Read-only fields
	ArchivedAt *time.Time `json:"archivedAt,omitempty"`

	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
}

Feature is a feature or service offered to a customer. For example: CPU-Hours, Tokens, API Calls, etc.

func (*Feature) Validate

func (f *Feature) Validate() error

Validate validates the feature.

type FeatureArchiveEvent

type FeatureArchiveEvent struct {
	Feature *Feature `json:"feature"`
	UserID  *string  `json:"userId,omitempty"`
}

FeatureArchiveEvent is an event that is emitted when a feature is archived

func NewFeatureArchiveEvent

func NewFeatureArchiveEvent(ctx context.Context, feature *Feature) FeatureArchiveEvent

NewFeatureArchiveEvent creates a new feature delete event

func (FeatureArchiveEvent) EventMetadata

func (e FeatureArchiveEvent) EventMetadata() metadata.EventMetadata

func (FeatureArchiveEvent) EventName

func (e FeatureArchiveEvent) EventName() string

func (FeatureArchiveEvent) Validate

func (e FeatureArchiveEvent) Validate() error

type FeatureConnector

type FeatureConnector interface {
	// Feature Management
	CreateFeature(ctx context.Context, feature CreateFeatureInputs) (Feature, error)
	// Should just use deletedAt, there's no real "archiving"
	ArchiveFeature(ctx context.Context, featureID models.NamespacedID) error
	ListFeatures(ctx context.Context, params ListFeaturesParams) (pagination.PagedResponse[Feature], error)
	GetFeature(ctx context.Context, namespace string, idOrKey string, includeArchived IncludeArchivedFeature) (*Feature, error)
}

TODO: refactor to service pattern

func NewFeatureConnector

func NewFeatureConnector(
	featureRepo FeatureRepo,
	meterService meterpkg.Service,
	publisher eventbus.Publisher,
) FeatureConnector

type FeatureCreateEvent

type FeatureCreateEvent struct {
	Feature *Feature `json:"feature"`
	UserID  *string  `json:"userId,omitempty"`
}

FeatureCreateEvent is an event that is emitted when a feature is created

func NewFeatureCreateEvent

func NewFeatureCreateEvent(ctx context.Context, feature *Feature) FeatureCreateEvent

NewFeatureCreateEvent creates a new feature create event

func (FeatureCreateEvent) EventMetadata

func (e FeatureCreateEvent) EventMetadata() metadata.EventMetadata

func (FeatureCreateEvent) EventName

func (e FeatureCreateEvent) EventName() string

func (FeatureCreateEvent) Validate

func (e FeatureCreateEvent) Validate() error

type FeatureInvalidFiltersError

type FeatureInvalidFiltersError struct {
	RequestedFilters    map[string]string
	MeterGroupByColumns []string
}

func (*FeatureInvalidFiltersError) Error

type FeatureInvalidMeterAggregationError

type FeatureInvalidMeterAggregationError struct {
	MeterSlug         string
	Aggregation       meter.MeterAggregation
	ValidAggregations []meter.MeterAggregation
}

func (*FeatureInvalidMeterAggregationError) Error

type FeatureNotFoundError

type FeatureNotFoundError struct {
	ID string
}

func (*FeatureNotFoundError) Error

func (e *FeatureNotFoundError) Error() string

type FeatureOrderBy

type FeatureOrderBy string

FeatureOrderBy is the order by clause for features

const (
	FeatureOrderByKey       FeatureOrderBy = "key"
	FeatureOrderByName      FeatureOrderBy = "name"
	FeatureOrderByCreatedAt FeatureOrderBy = "created_at"
	FeatureOrderByUpdatedAt FeatureOrderBy = "updated_at"
)

func (FeatureOrderBy) Values

func (f FeatureOrderBy) Values() []FeatureOrderBy

type FeatureRepo

type FeatureRepo interface {
	CreateFeature(ctx context.Context, feature CreateFeatureInputs) (Feature, error)
	ArchiveFeature(ctx context.Context, featureID models.NamespacedID) error
	ListFeatures(ctx context.Context, params ListFeaturesParams) (pagination.PagedResponse[Feature], error)
	HasActiveFeatureForMeter(ctx context.Context, namespace string, meterSlug string) (bool, error)

	GetByIdOrKey(ctx context.Context, namespace string, idOrKey string, includeArchived bool) (*Feature, error)
	entutils.TxCreator
	entutils.TxUser[FeatureRepo]
}

type FeatureWithNameAlreadyExistsError

type FeatureWithNameAlreadyExistsError struct {
	Name string
	ID   string
}

func (*FeatureWithNameAlreadyExistsError) Error

type ForbiddenError

type ForbiddenError struct {
	Msg string
	ID  string
}

func (*ForbiddenError) Error

func (e *ForbiddenError) Error() string

type IncludeArchivedFeature

type IncludeArchivedFeature bool
const (
	IncludeArchivedFeatureTrue  IncludeArchivedFeature = true
	IncludeArchivedFeatureFalse IncludeArchivedFeature = false
)

type ListFeaturesParams

type ListFeaturesParams struct {
	IDsOrKeys       []string
	Namespace       string
	MeterSlugs      []string
	IncludeArchived bool
	Page            pagination.Page
	OrderBy         FeatureOrderBy
	Order           sortx.Order
	// will be deprecated
	Limit int
	// will be deprecated
	Offset int
}

type MeterGroupByFilters

type MeterGroupByFilters map[string]string

MeterGroupByFilters is a map of filters that can be applied to a meter when querying the usage for a feature.

func (MeterGroupByFilters) Validate

func (f MeterGroupByFilters) Validate(meter meter.Meter) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL