core

package
v0.0.21-alpha Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2024 License: Apache-2.0 Imports: 16 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) Description

func (e Error) Description() string

func (Error) GRPCCode

func (e Error) GRPCCode() codes.Code

func (Error) HTTPCode

func (e Error) HTTPCode() int

func (Error) ID

func (e Error) ID() string

func (Error) IsDeprecated

func (e Error) IsDeprecated() bool

func (Error) Localization

func (e Error) Localization() Localization

func (Error) Message

func (e Error) Message() string

type ErrorBuilder

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

ErrorBuilder is responsible for creating Error instances.

func NewErrorBuilder

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

NewErrorBuilder creates a new instance of ErrorBuilder.

func (*ErrorBuilder) NewError

func (b *ErrorBuilder) NewError(
	id string,
	message string,
	grpcCode codes.Code,
	httpCode int,
	description string,
	isDeprecated bool,
	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) AddDescriptionTranslation

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

func (*Localization) AddMessageTranslation

func (l *Localization) AddMessageTranslation(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) Description

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

func (Localization) Message

func (l Localization) Message() 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
	DefaultLocale language.Tag
	Errors        []Error
}

func (Spec) HasTimestampArguments

func (s Spec) HasTimestampArguments() bool

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