settings

package
v1.0.2-gitspaces-beta Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// KeySecretScanningEnabled [bool] enables secret scanning if set to true.
	KeySecretScanningEnabled     Key = "secret_scanning_enabled"
	DefaultSecretScanningEnabled     = false
	KeyFileSizeLimit             Key = "file_size_limit"
	DefaultFileSizeLimit             = int64(1e+8) // 100 MB
)

Functions

func RepoGet

func RepoGet[T any](
	ctx context.Context,
	s *Service,
	repoID int64,
	key Key,
	dflt T,
) (T, error)

RepoGet is a helper method for getting a setting of a specific type for a repo.

func RepoGetRequired

func RepoGetRequired[T any](
	ctx context.Context,
	s *Service,
	repoID int64,
	key Key,
) (T, error)

RepoGetRequired is a helper method for getting a setting of a specific type for a repo. If the setting isn't found, an error is returned.

Types

type Key

type Key string

type KeyValue

type KeyValue struct {
	Key   Key
	Value any
}

KeyValue is a struct used for upserting many entries.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is used to enhance interaction with the settings store.

func NewService

func NewService(
	settingsStore appstore.SettingsStore,
) *Service

func ProvideService

func ProvideService(
	settingsStore store.SettingsStore,
) *Service

func (*Service) Get

func (s *Service) Get(
	ctx context.Context,
	scope enum.SettingsScope,
	scopeID int64,
	key Key,
	out any,
) (bool, error)

Get returns the value of the setting with the given key for the given scope.

func (*Service) Map

func (s *Service) Map(
	ctx context.Context,
	scope enum.SettingsScope,
	scopeID int64,
	handlers ...SettingHandler,
) error

Map maps all available settings using the provided handlers for the given scope.

func (*Service) RepoGet

func (s *Service) RepoGet(
	ctx context.Context,
	repoID int64,
	key Key,
	out any,
) (bool, error)

RepoGet returns the value of the setting with the given key for the given repo.

func (*Service) RepoMap

func (s *Service) RepoMap(
	ctx context.Context,
	repoID int64,
	handlers ...SettingHandler,
) error

RepoMap maps all available settings using the provided handlers for the given repo.

func (*Service) RepoSet

func (s *Service) RepoSet(
	ctx context.Context,
	repoID int64,
	key Key,
	value any,
) error

RepoSet sets the value of the setting with the given key for the given repo.

func (*Service) RepoSetMany

func (s *Service) RepoSetMany(
	ctx context.Context,
	repoID int64,
	keyValues ...KeyValue,
) error

RepoSetMany sets the value of the settings with the given keys for the given repo.

func (*Service) Set

func (s *Service) Set(
	ctx context.Context,
	scope enum.SettingsScope,
	scopeID int64,
	key Key,
	value any,
) error

Set sets the value of the setting with the given key for the given scope.

func (*Service) SetMany

func (s *Service) SetMany(
	ctx context.Context,
	scope enum.SettingsScope,
	scopeID int64,
	keyValues ...KeyValue,
) error

SetMany sets the value of the settings with the given keys for the given scope.

type SettingHandler

type SettingHandler interface {
	Key() Key
	Required() bool
	Handle(ctx context.Context, raw []byte) error
}

SettingHandler is an abstraction of a component that's handling a single setting value as part of calling service.Map.

func Mapping

func Mapping[T any](key Key, target *T) SettingHandler

Mapping returns a SettingHandler that maps the value of the setting with the given key to the target.

func MappingRequired

func MappingRequired[T any](key Key, target *T) SettingHandler

MappingRequired returns a SettingHandler that maps the value of the setting with the given key to the target. If the setting wasn't found an error is returned.

Jump to

Keyboard shortcuts

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