core

package
v0.0.9-alpha Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidArgumentType = errors.New("not a valid ArgumentType")

Functions

This section is empty.

Types

type Argument

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

Argument represents an argument used in the error messages.

func NewArgument

func NewArgument(name, description, typ string) (Argument, error)

func (Argument) Description

func (a Argument) Description() string

func (Argument) Name

func (a Argument) Name() string

func (Argument) Typ

func (a Argument) Typ() ArgumentType

type ArgumentType

type ArgumentType int8

ArgumentType represents the type of the argument.

ENUM( unknown string int float bool timestamp )

const (
	// ArgumentTypeUnknown is a ArgumentType of type Unknown.
	ArgumentTypeUnknown ArgumentType = iota
	// ArgumentTypeString is a ArgumentType of type String.
	ArgumentTypeString
	// ArgumentTypeInt is a ArgumentType of type Int.
	ArgumentTypeInt
	// ArgumentTypeFloat is a ArgumentType of type Float.
	ArgumentTypeFloat
	// ArgumentTypeBool is a ArgumentType of type Bool.
	ArgumentTypeBool
	// ArgumentTypeTimestamp is a ArgumentType of type Timestamp.
	ArgumentTypeTimestamp
)

func ParseArgumentType

func ParseArgumentType(name string) (ArgumentType, error)

ParseArgumentType attempts to convert a string to a ArgumentType.

func (ArgumentType) MarshalText

func (x ArgumentType) MarshalText() ([]byte, error)

MarshalText implements the text marshaller method.

func (*ArgumentType) Scan

func (x *ArgumentType) Scan(value interface{}) (err error)

Scan implements the Scanner interface.

func (ArgumentType) String

func (x ArgumentType) String() string

String implements the Stringer interface.

func (*ArgumentType) UnmarshalText

func (x *ArgumentType) UnmarshalText(text []byte) error

UnmarshalText implements the text unmarshaller method.

func (ArgumentType) Value

func (x ArgumentType) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Config

type Config struct {
	SpecPath string
	ExportGo ExportGo
}

type Error

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

func (Error) Arguments

func (e Error) Arguments() []Argument

func (Error) Code

func (e Error) Code() string

func (Error) Description

func (e Error) Description() string

func (Error) Domain

func (e Error) Domain() string

func (Error) GrpcCode

func (e Error) GrpcCode() codes.Code

func (Error) HTTPCode

func (e Error) HTTPCode() int

func (Error) InternalMessage

func (e Error) InternalMessage() string

func (Error) Namespace

func (e Error) Namespace() string

func (Error) PublicMessage

func (e Error) PublicMessage() string

func (Error) Title

func (e Error) Title() string

func (Error) Translations

func (e Error) Translations() Localization

func (Error) UID

func (e Error) UID() string

type ErrorBuilder

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

ErrorBuilder is responsible for creating Error instances.

func NewErrorBuilder

func NewErrorBuilder(specVersion, domain, namespace, defaultLocale string) (*ErrorBuilder, error)

NewErrorBuilder creates a new instance of ErrorBuilder.

func (*ErrorBuilder) NewError

func (b *ErrorBuilder) NewError(
	code string,
	grpcCode codes.Code,
	httpCode int,
	description string,
	title string,
	publicMessage string,
	internalMessage string,
	deprecatedMessage string,
	arguments []Argument,
	localization Localization,
) (Error, error)

NewError creates a new instance of Error.

type ExportGo

type ExportGo struct {
	PackageName string
	OutputPath  string
}

type GoExporter

type GoExporter interface {
	Export(cfg ExportGo, spec Spec) error
}

GoExporter is responsible for exporting the parsed errors to Go code.

type Importer

type Importer interface {
	Import(reader io.Reader) (Spec, error)
}

type Localization

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

func NewLocalization

func NewLocalization() Localization

func (*Localization) AddArgumentTranslation

func (l *Localization) AddArgumentTranslation(name, description, lang string) error

func (*Localization) AddDeprecatedTranslation

func (l *Localization) AddDeprecatedTranslation(lang string, val string) error

func (*Localization) AddDescriptionTranslation

func (l *Localization) AddDescriptionTranslation(lang string, val string) error

func (*Localization) AddInternalMessageTranslation

func (l *Localization) AddInternalMessageTranslation(lang string, val string) error

func (*Localization) AddPublicMessageTranslation

func (l *Localization) AddPublicMessageTranslation(lang string, val string) error

func (*Localization) AddTitleTranslation

func (l *Localization) AddTitleTranslation(lang string, val string) error

func (Localization) AllLanguages

func (l Localization) AllLanguages() []language.Tag

func (Localization) Arguments

func (l Localization) Arguments() map[string]map[language.Tag]string

func (Localization) Deprecated

func (l Localization) Deprecated() map[language.Tag]string

func (Localization) Description

func (l Localization) Description() map[language.Tag]string

func (Localization) InternalMessage

func (l Localization) InternalMessage() map[language.Tag]string

func (Localization) PublicMessage

func (l Localization) PublicMessage() map[language.Tag]string

func (Localization) Title

func (l Localization) Title() map[language.Tag]string

type Manager

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

func NewManager

func NewManager(importer Importer, goExporter GoExporter) *Manager

func (*Manager) Generate

func (m *Manager) Generate(cfg Config) error

type Spec

type Spec struct {
	Version       string
	Domain        string
	Namespace     string
	DefaultLocale language.Tag
	Errors        []Error
}

type TemplateValidator

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

TemplateValidator is an implementation of core.TemplateValidator interface.

func NewTemplateValidator

func NewTemplateValidator(cfg *TemplateValidatorConfig) *TemplateValidator

NewTemplateValidator returns a new instance of TemplateValidator.

func (*TemplateValidator) Validate

func (p *TemplateValidator) Validate(txt string) (err error)

Validate implements core.TemplateValidator interface.

type TemplateValidatorConfig

type TemplateValidatorConfig struct {
	Debug     bool
	Arguments map[string]struct{}
}

TemplateValidatorConfig is a configuration for TemplateValidator.

Jump to

Keyboard shortcuts

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