template

package
v0.5.9 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReservedName_SystemDefault = "system-default"
)

Variables

View Source
var (
	ErrDuplicate = errors.New("name already exist")
)

Functions

func IsReservedName added in v0.5.0

func IsReservedName(templateName string) bool

func RenderBody added in v0.5.0

func RenderBody(templateBody string, aStruct interface{}) (string, error)

func RenderWithEnrichedDefault added in v0.5.0

func RenderWithEnrichedDefault(templateBody string, templateVars []Variable, requestVariables map[string]string) (string, error)

Types

type Filter

type Filter struct {
	Tag string
}

type NotFoundError

type NotFoundError struct {
	Name string
}

func (NotFoundError) Error

func (err NotFoundError) Error() string

type Repository

type Repository interface {
	Upsert(context.Context, *Template) error
	List(context.Context, Filter) ([]Template, error)
	GetByName(context.Context, string) (*Template, error)
	Delete(context.Context, string) error
}

type Service

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

Service handles business logic

func NewService

func NewService(repository Repository) *Service

NewService returns repository struct

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, name string) error

func (*Service) GetByName

func (s *Service) GetByName(ctx context.Context, name string) (*Template, error)

func (*Service) List

func (s *Service) List(ctx context.Context, flt Filter) ([]Template, error)

func (*Service) Render

func (s *Service) Render(ctx context.Context, name string, requestVariables map[string]string) (string, error)

TODO might want to delete this and use the static function instead

func (*Service) Upsert

func (s *Service) Upsert(ctx context.Context, template *Template) error

type Template

type Template struct {
	ID        uint64     `json:"id"`
	Name      string     `json:"name" validate:"required"`
	Body      string     `json:"body" validate:"required"`
	Tags      []string   `json:"tags" validate:"required"`
	Variables []Variable `json:"variables" validate:"required,dive,required"`
	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt time.Time  `json:"updated_at"`
}

type TemplateFile added in v0.5.0

type TemplateFile struct {
	Name       string              `yaml:"name"`
	ApiVersion string              `yaml:"apiVersion"`
	Type       string              `yaml:"type"`
	Body       []templatedRuleFile `yaml:"body"`
	Tags       []string            `yaml:"tags"`
	Variables  []Variable          `yaml:"variables"`
}

type Variable

type Variable struct {
	Name        string `json:"name" validate:"required"`
	Type        string `json:"type" validate:"required"`
	Default     string `json:"default"`
	Description string `json:"description"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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