package config
import "hauru.club/x/okrzeja/service/config"
Package config implements service for manipulating static and dynamic application's configuration.
Index ¶
- Variables
- type Dynamic
- type ReadRepository
- type Service
- func (s *Service) Init(ctx context.Context) error
- func (s *Service) Latest(ctx context.Context) (*Dynamic, error)
- func (s *Service) PushNewVersion(ctx context.Context, c Dynamic) error
- func (s *Service) RegistrationEnabled(ctx context.Context) (bool, error)
- type Static
- type WriteRepository
- type WriteRequest
Variables ¶
var ErrConfigNotFound = errors.New("config: config not found")
ErrConfigNotFound is being returned when there is no config in the system at all.
Types ¶
type Dynamic ¶
type Dynamic struct {
// RegisterFrom is switch for register form. If it's true, then
// registration form is active and random users from internet
// are able to create accounts in the website.
RegisterFrom bool `json:"registerForm"`
}
Dynamic holds configuration variables for application that can be changed at runtime.
type ReadRepository ¶
type ReadRepository interface {
// ReadLatestConfig returns latest blob of bytes with encoded config
// as JSON document.
//
// It can return ErrConfigNotFound.
ReadLatestConfig(context.Context) ([]byte, error)
}
ReadRepository reads configuration from storage.
type Service ¶
type Service struct {
WriteRepository
ReadRepository
}
Service manages dynamic configuration of system.
func (*Service) Init ¶
Init pushes default dynamic config to the database. If there is already existing dynamic configuration, it does nothing.
func (*Service) Latest ¶
Latest returns the latest current version of dynamic config during the time of read.
func (*Service) PushNewVersion ¶
PushNewVersion pushes new version of dynamic config and make it live immediately.
func (*Service) RegistrationEnabled ¶
RegistrationEnabled returns true if registration for appliation is currently enabled.
type Static ¶
type Static struct {
// Environment type, which application is run at.
//
// Can be: TEST (test), DEV (development) or PRD (production).
Environment string `envconfig:"env" default:"PRD"`
// Host part of the address to listen.
Host string `default:"127.0.0.1"`
// Port part of the address to listen.
Port int32 `default:"8080"`
// DatabasePath is path which points to the database file.
DatabasePath string `default:"okrzeja.sqlite" split_words:"true"`
}
Static holds configuration variables for application that cannot be changed at runtime and are stored in the environmental variables.
func ReadStatic ¶
ReadStatic reads Static configuration from environmental variables.
func (*Static) Address ¶
Address returns configured listen address.
type WriteRepository ¶
type WriteRepository interface {
// WriteConfig writes new version of configuration to the storage.
//
// It shouldn't purge the current version of config, instead, new
// entry should be added to the storage and previous kept in some
// kid of archive.
WriteConfig(context.Context, WriteRequest) error
}
WriteRepository writes config to the internal storage.
type WriteRequest ¶
type WriteRequest struct {
// ID is unique identifier of current config version.
ID uuid.UUID
// NewConfig encoded as json blob of bytes.
NewConfig []byte
// CreatedAt is time when config was created.
CreatedAt time.Time
}
Source Files ¶
config.go
- Version
- v0.0.0-20231010043146-4292577f982b (latest)
- Published
- Oct 10, 2023
- Platform
- linux/amd64
- Imports
- 7 packages
- Last checked
- 1 year ago –
Tools for package owners.