config

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2023 License: MIT Imports: 10 Imported by: 1

Documentation

Overview

Package config load settings from external files or environment variables and manage their values.

Index

Constants

View Source
const ConfigFilePath string = ".spare.yml"

ConfigFilePath is the path of the configuration file.

Variables

View Source
var (
	// ErrConfigFileAlreadyExists is an error that occurs when the config file already exists.
	ErrConfigFileAlreadyExists = fmt.Errorf("%s config file already exists", ConfigFilePath)
	// ErrInvalidRegion is an error that occurs when the region is invalid.
	ErrInvalidRegion = errors.New("invalid region")
	// ErrInvalidBucket is an error that occurs when the bucket is invalid.
	ErrInvalidBucket = errors.New("invalid bucket")
	// ErrInvalidSpareTemplateVersion is an error that occurs when the spare template version is invalid.
	ErrInvalidSpareTemplateVersion = errors.New("invalid spare template version")
	// ErrInvalidDeployTarget is an error that occurs when the deploy target is invalid.
	ErrInvalidDeployTarget = errors.New("invalid deploy target")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	SpareTemplateVersion TemplateVersion `yaml:"spareTemplateVersion"`
	// DeployTarget is the path of the deploy target (it's SPA).
	DeployTarget DeployTarget `yaml:"deployTarget"`
	// Region is AWS region.
	Region model.Region `yaml:"region"`
	// CustomDomain is the domain name of the CloudFront.
	// If you do not specify this, the CloudFront default domain name is used.
	CustomDomain model.Domain `yaml:"customDomain"`
	// S3BucketName is the name of the S3 bucket.
	S3BucketName model.BucketName `yaml:"s3BucketName"`
	// AllowOrigins is the list of domains that are allowed to access the SPA.
	AllowOrigins            model.AllowOrigins `yaml:"allowOrigins"`
	DebugLocalstackEndpoint model.Endpoint     `yaml:"debugLocalstackEndpoint"`
}

Config is a struct that corresponds to the configuration file ".spare.yml".

func NewConfig

func NewConfig() *Config

NewConfig returns a new Config.

func (*Config) DefaultS3BucketName

func (c *Config) DefaultS3BucketName() model.BucketName

DefaultS3BucketName returns the default S3 bucket name.

func (*Config) Read

func (c *Config) Read(r io.Reader) (err error)

Read reads the Config from the io.Reader.

func (*Config) Validate

func (c *Config) Validate(debugMode bool) error

Validate validates the Config. If debugMode is true, it validates the DebugLocalstackEndpoint.

func (*Config) Write

func (c *Config) Write(w io.Writer) (err error)

Write writes the Config to the io.Writer.

type DeployTarget

type DeployTarget string

DeployTarget is a type that represents a deploy target path.

func (DeployTarget) String

func (d DeployTarget) String() string

String returns the string representation of DeployTarget.

func (DeployTarget) Validate

func (d DeployTarget) Validate() error

Validate validates DeployTarget. If DeployTarget is invalid, it returns an error. DeployTarget is invalid if it is empty.

type S3

type S3 struct {
	// Bucket is the name of the S3 bucket.
	Bucket model.BucketName `env:"spare_BUCKET"`
	// Region is the name of the AWS region.
	Region model.Region `env:"spare_REGION" envDefault:"us-east-1"`
}

S3 is a struct that contains the settings for the S3 storage.

func NewS3

func NewS3() (*S3, error)

NewS3 returns a new S3 struct.

type TemplateVersion

type TemplateVersion string

TemplateVersion is a type that represents a spare template version.

const CurrentSpareTemplateVersion TemplateVersion = "0.0.1"

CurrentSpareTemplateVersion is the version of the template.

func (TemplateVersion) String

func (t TemplateVersion) String() string

String returns the string representation of TemplateVersion.

func (TemplateVersion) Validate

func (t TemplateVersion) Validate() error

Validate validates TemplateVersion. If TemplateVersion is invalid, it returns an error. TemplateVersion is invalid if it is empty.

Jump to

Keyboard shortcuts

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