template

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: Apache-2.0 Imports: 16 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DelimMessageLeft  = "{{"
	DelimMessageRight = "}}"
)
View Source
const (
	ReservedName_SystemDefault = "system-default"
)

Variables

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

Functions

func IsReservedName

func IsReservedName(templateName string) bool

func MessageContentByReceiverType added in v0.7.1

func MessageContentByReceiverType(messagesTemplate []Message, receiverType string) (string, error)

func RenderBody

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

func RenderWithEnrichedDefault

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

Types

type File added in v0.7.1

type File struct {
	Name       string     `yaml:"name"`
	ApiVersion string     `yaml:"apiVersion"`
	Type       string     `yaml:"type"`
	Body       []FileBody `yaml:"body"`
	Message    Message    `yaml:"message"`
	Tags       []string   `yaml:"tags"`
	Delete     bool       `yaml:"delete"`
	Variables  []Variable `yaml:"variables"`
}

func YamlStringToFile added in v0.7.1

func YamlStringToFile(str string) (*File, error)

type FileBody added in v0.7.1

type FileBody struct {
	Rule    `yaml:",inline"`
	Message `yaml:",inline"`
}

type Filter

type Filter struct {
	Tag string
}

type Message added in v0.7.1

type Message struct {
	ReceiverType string `yaml:"receiver_type,omitempty"` // mandatory
	Content      string `yaml:"content,omitempty"`
}

func MessagesFromBody added in v0.7.1

func MessagesFromBody(tpl *Template) ([]Message, error)

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 Rule added in v0.7.1

type Rule struct {
	Record      string            `yaml:"record,omitempty"`
	Alert       string            `yaml:"alert,omitempty"`
	Expr        string            `yaml:"expr,omitempty"` // mandatory
	For         string            `yaml:"for,omitempty"`
	Labels      map[string]string `yaml:"labels,omitempty"`
	Annotations map[string]string `yaml:"annotations,omitempty"`
}

func RulesBody added in v0.7.1

func RulesBody(tpl *Template) ([]Rule, 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"`
}

func FromV1beta1Proto added in v0.6.7

func FromV1beta1Proto(proto *sirenv1beta1.Template) Template

func ParseFile added in v0.7.1

func ParseFile(fl *File) (*Template, error)

func (*Template) ToV1beta1Proto added in v0.6.7

func (t *Template) ToV1beta1Proto() *sirenv1beta1.Template

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