Documentation ¶
Index ¶
- Variables
- func ApplyFromDecl(decl ast.Decl, result *Map) (err error)
- func IsDirective(c string) bool
- type FilterFunc
- func Exactly(s string) FilterFunc
- func HasKey(parts ...string) FilterFunc
- func HasPrefix(prefix string) FilterFunc
- func HasQualifier(qualifier string) FilterFunc
- func HasSuffix(suffix string) FilterFunc
- func HasTool(tool string) FilterFunc
- func Matches(pattern string) FilterFunc
- func OneOf(filters ...FilterFunc) FilterFunc
- type Line
- type List
- type Map
- type OptionList
- func (ol *OptionList) GetAll(key string, def []string) (val []string, ok bool)
- func (ol *OptionList) GetOne(key, fallback string) (val string, ok bool)
- func (ol *OptionList) GobDecode(bytes []byte) error
- func (ol *OptionList) GobEncode() ([]byte, error)
- func (ol *OptionList) Has(key string) bool
- func (ol *OptionList) HasOneOf(keys ...string) bool
- func (ol *OptionList) Set(key string, val []string)
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidDirective = errors.New("invalid directive")
Functions ¶
func ApplyFromDecl ¶
ApplyFromDecl applies the comments from a declaration to the result map
func IsDirective ¶
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 ¶
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 ¶
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)
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) Some ¶
func (l List) Some(some FilterFunc) bool
type Map ¶
type Map = orderedmap.OrderedMap[*ast.Ident, List]
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