Documentation
¶
Overview ¶
Package templates provides stack templates (#33, #34, ADR-0051): a built-in catalog, catalogs from registry.json URLs, and templates users saved. A template is a compose file, an .env.example whose comments describe its variables, and a description.
Index ¶
- Constants
- type Input
- type Registries
- type Service
- func (s *Service) Create(ctx context.Context, in Input, user string) (Template, error)
- func (s *Service) Delete(ctx context.Context, id string) error
- func (s *Service) Get(ctx context.Context, source, id string) (Template, error)
- func (s *Service) List(ctx context.Context) ([]Summary, []SourceError, error)
- func (s *Service) RegistryURLs(ctx context.Context) ([]string, error)
- func (s *Service) SetRegistryURLs(ctx context.Context, urls []string) ([]string, error)
- func (s *Service) Update(ctx context.Context, id string, in Input) (Template, error)
- type SourceError
- type Store
- type Summary
- type Template
- type Variable
Constants ¶
const ( SourceBuiltin = "builtin" SourceCustom = "custom" )
Sources of templates besides registry URLs.
const MaxFile = 256 << 10
MaxFile is the largest compose file or .env.example of a template.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Input ¶
type Input struct {
Name string `json:"name"`
Description string `json:"description"`
Compose string `json:"compose"`
Env string `json:"env"`
}
Input creates or changes a custom template. Keep in sync with api/openapi.yaml.
type Registries ¶
type Registries struct {
Client *http.Client
Now func() time.Time
// contains filtered or unexported fields
}
Registries reads registry.json files over HTTP and caches them.
type Service ¶
type Service struct {
Store Store
Registry *Registries
Now func() time.Time
}
Service lists and fetches templates.
func (*Service) List ¶
List returns every template: built-in, custom and from the registries. A registry that cannot be read is reported and skipped.
func (*Service) RegistryURLs ¶
RegistryURLs returns the configured registry URLs.
func (*Service) SetRegistryURLs ¶
SetRegistryURLs replaces the registry URLs.
type SourceError ¶
SourceError is a registry that could not be read.
type Store ¶
type Store interface {
ListStackTemplates(ctx context.Context) ([]db.StackTemplate, error)
GetStackTemplate(ctx context.Context, id int64) (db.StackTemplate, error)
CreateStackTemplate(ctx context.Context, arg db.CreateStackTemplateParams) (db.StackTemplate, error)
UpdateStackTemplate(ctx context.Context, arg db.UpdateStackTemplateParams) (db.StackTemplate, error)
DeleteStackTemplate(ctx context.Context, id int64) (int64, error)
GetSetting(ctx context.Context, key string) (string, error)
SetSetting(ctx context.Context, arg db.SetSettingParams) error
}
Store is the database; *db.Queries implements it.
type Summary ¶
type Summary struct {
// Source is builtin, custom or the URL of a registry.
Source string `json:"source"`
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Categories []string `json:"categories,omitempty"`
Logo string `json:"logo,omitempty"`
Documentation string `json:"documentation,omitempty"`
UpdatedAt *time.Time `json:"updatedAt,omitempty"`
}
Summary describes a template in a catalog. Keep in sync with api/openapi.yaml.
type Template ¶
type Template struct {
Summary
Compose string `json:"compose"`
Env string `json:"env"`
Variables []Variable `json:"variables"`
}
Template is a template with its files and variables. Keep in sync with api/openapi.yaml.
type Variable ¶
type Variable struct {
Name string `json:"name"`
Default string `json:"default"`
Description string `json:"description,omitempty"`
// Secret is guessed from the name (password, secret, token, key).
Secret bool `json:"secret"`
}
Variable is a variable of .env.example. Keep in sync with api/openapi.yaml.