decorators

package
v0.0.1-alpha Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidDirective = errors.New("invalid directive")

Functions

func ApplyFromDecl

func ApplyFromDecl(decl ast.Decl, result *Map) (err error)

ApplyFromDecl applies the comments from a declaration to the result map

func IsDirective

func IsDirective(c string) bool

IsDirective reports whether c is a comment directive. This code is also in go/printer. Copied from private go/ast/ast.go IsDirective

Types

type FilterFunc

type FilterFunc func(d Line) bool

func Exactly

func Exactly(s string) FilterFunc

func HasKey

func HasKey(parts ...string) FilterFunc

func HasPrefix

func HasPrefix(prefix string) FilterFunc

func HasQualifier

func HasQualifier(qualifier string) FilterFunc

func HasSuffix

func HasSuffix(suffix string) FilterFunc

func HasTool

func HasTool(tool string) FilterFunc

func Matches

func Matches(pattern string) FilterFunc

func OneOf

func OneOf(filters ...FilterFunc) FilterFunc

type Line

type Line struct {
	Tool      string
	Name      string
	Qualifier string
	Options   *OptionList
}

func Parse

func Parse(d string) (dir Line, err error)

Parse extracts data from a directive string.

Example: kibu:endpoint method=GET path=/api/v1/users

Path is an unquoted string literal (kibu:endpoint) Path contains two parts tool (kibu) and name (endpoint) separated by a colon Path is required

value is an unquoted string literal (method=GET path=/api/v1/users) value is optional A value is a list of Options separated by a space An Option is a key value pair separated by an equals sign An Option key is an unquoted string literal (method) An Option value is an unquoted string literal (GET)

func (Line) String

func (d Line) String() string

type List

type List []Line

func FromCommentGroup

func FromCommentGroup(d *ast.CommentGroup) (result List, err error)

FromCommentGroup returns a list of directives by parsing an *ast.CommentGroup.

func (List) Filter

func (l List) Filter(filter FilterFunc) List

func (List) Find

func (l List) Find(predicate FilterFunc) (Line, bool)

func (List) Some

func (l List) Some(some FilterFunc) bool

type Map

func FromDecls

func FromDecls(decls []ast.Decl) (result *Map, err error)

FromDecls returns a list of directives cached by *ast.Ident

func NewMap

func NewMap() *Map

type OptionList

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

func NewOptionList

func NewOptionList() *OptionList

func NewOptionListWithDefaults

func NewOptionListWithDefaults(defaults map[string][]string) *OptionList

func (*OptionList) GetAll

func (ol *OptionList) GetAll(key string, def []string) (val []string, ok bool)

GetAll returns a list of option values by key

func (*OptionList) GetOne

func (ol *OptionList) GetOne(key, fallback string) (val string, ok bool)

GetOne returns a single option value by its key If the option does not exist an empty string is returned

func (*OptionList) GobDecode

func (ol *OptionList) GobDecode(bytes []byte) error

func (*OptionList) GobEncode

func (ol *OptionList) GobEncode() ([]byte, error)

func (*OptionList) Has

func (ol *OptionList) Has(key string) bool

Has checks if an option is present by its key it is possible for a key to be present with no value

func (*OptionList) HasOneOf

func (ol *OptionList) HasOneOf(keys ...string) bool

func (*OptionList) Set

func (ol *OptionList) Set(key string, val []string)

Set sets a single option value by its key

Jump to

Keyboard shortcuts

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