Check for existance

Signed-off-by: jolheiser <john.olheiser@gmail.com>
pull/11/head
jolheiser 2020-11-29 23:11:52 -06:00
parent 17dd27fe21
commit 2f4cfcd25d
Signed by: jolheiser
GPG Key ID: B853ADA5DA7BBF7A
2 changed files with 21 additions and 0 deletions

View File

@ -2,6 +2,19 @@ package registry
import "fmt" import "fmt"
type ErrTemplateExists struct {
Name string
}
func (e ErrTemplateExists) Error() string {
return fmt.Sprintf("template %s already exists", e.Name)
}
func IsErrTemplateExists(err error) bool {
_, ok := err.(ErrTemplateExists)
return ok
}
type ErrTemplateNotFound struct { type ErrTemplateNotFound struct {
Name string Name string
} }

View File

@ -50,6 +50,10 @@ func (r *Registry) GetTemplate(name string) (*Template, error) {
// DownloadTemplate downloads and adds a new Template to the Registry // DownloadTemplate downloads and adds a new Template to the Registry
func (r *Registry) DownloadTemplate(name, repo, branch string) (*Template, error) { func (r *Registry) DownloadTemplate(name, repo, branch string) (*Template, error) {
if _, err := r.GetTemplate(name); err == nil {
return nil, ErrTemplateExists{Name: name}
}
t := &Template{ t := &Template{
reg: r, reg: r,
Name: name, Name: name,
@ -68,6 +72,10 @@ func (r *Registry) DownloadTemplate(name, repo, branch string) (*Template, error
// SaveTemplate saves a local Template to the Registry // SaveTemplate saves a local Template to the Registry
func (r *Registry) SaveTemplate(name, path string) (*Template, error) { func (r *Registry) SaveTemplate(name, path string) (*Template, error) {
if _, err := r.GetTemplate(name); err == nil {
return nil, ErrTemplateExists{Name: name}
}
t := &Template{ t := &Template{
reg: r, reg: r,
Name: name, Name: name,