functions

package
v0.0.0-...-43c8ab9 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

README

Package cloudeng.io/go/cmd/goannotate/annotators/functions

CircleCI Go Report Card

import cloudeng.io/go/cmd/goannotate/annotators/functions

Constants

LogCallWithContextDescription
LogCallWithContextDescription = `
LogCallWithContext provides a functon call generator for generating calls to
functions with the following signature:

  func (ctx <contextType>, functionName, format string, arguments ...interface{}) func(ctx <contextType>, format string, namedResults ...interface{}) 

These are invoked via defer as show below:

  defer <call>(ctx, "<function-name>",  "<format>", <parameters>....)(ctx, "<format>", <results>)

The actual type of the context is determined by the ContextType configuration
field. The parameters and named results are captured and passed to the logging
call according to cloudeng.io/go/derive.ArgsForParams and ArgsForResults.
The logging function must return a function that is defered to capture named
results and log them on function exit.
`

LogCallWithContextDescription documents LogCallWithContext.

SimpleLogCallDescription
SimpleLogCallDescription = `
SimpleLogCall provides a functon call generator for generating calls to
functions with the same signature log.Callf and fmt.Printf.
`

SimpleLogCallDescription documents SimpleLogCall.

Functions

Func CallGenerators
func CallGenerators() []string

CallGenerators lists all of the available CallGenerators.

Func RegisterCallGenerator
func RegisterCallGenerator(callGenerator CallGenerator)

RegisterCallGenerator registers a new function call generator.

Types

Type CallGenerator
type CallGenerator interface {
	// UnmarshalYAML unmarshals the annotator's yaml configuration.
	UnmarshalYAML(buf []byte) error
	// Import returns the import path for the function to be generated by
	// Generate.
	Import() string
	// Generate creates the appropriate call code and import path for
	// the function to be used as an annotation.
	Generate(*token.FileSet, *types.Func, *ast.FuncDecl) (string, error)
	// Describe returns a description for the function annotation.
	Describe() string
}

CallGenerator represents the ability to generate code for a function call using arguments taken from a function call signature.

Functions
func Lookup(typeName string) CallGenerator

Lookup returns the CallGenerator, if any, with the specified type.

Type EssentialOptions
type EssentialOptions struct {
	Type         string `yaml:"type" annotator:"name of annotator type."`
	ImportPath   string `yaml:"importPath" annotator:"import path for the logging function."`
	FunctionName string `yaml:"functionName" annotator:"name of the function to be invoked."`
}

EssentialOptions represents the configuration options required for all function generators.

Type LogCallWithContext
type LogCallWithContext struct {
	EssentialOptions `yaml:",inline"`
	ContextType      string `yaml:"contextType" annotator:"type for the context parameter and result."`
}

LogCallWithContext represents a function call generator for a logging call with the following signature:

func (ctx <contextType>, functionName, callerLocation, format string, arguments ...interface{}) func(ctx <contextType>, format string, namedResults ...interface{})

See LogCallWithContextDescription for a complete description.

Methods
func (lc *LogCallWithContext) Describe() string

Describe implements functions.CallGenerator.

func (lc *LogCallWithContext) Generate(fset *token.FileSet, fn *types.Func, decl *ast.FuncDecl) (string, error)
func (lc *LogCallWithContext) Import() string

Import implements functions.CallGenerator.

func (lc *LogCallWithContext) UnmarshalYAML(buf []byte) error

UnmarshalYAML implements functions.CallGenerator.

Type SimpleLogCall
type SimpleLogCall struct {
	EssentialOptions `yaml:",inline"`
	ContextType      string `yaml:"contextType" annotator:"type for the context parameter and result."`
}

SimpleLogCall represents a function call generator for a logging call with the same signature as log.Callf and fmt.Printf.

Methods
func (sl *SimpleLogCall) Describe() string

Describe implements functions.CallGenerator.

func (sl *SimpleLogCall) Generate(fset *token.FileSet, fn *types.Func, decl *ast.FuncDecl) (string, error)
func (sl *SimpleLogCall) Import() string

Import implements functions.CallGenerator.

func (sl *SimpleLogCall) UnmarshalYAML(buf []byte) error

UnmarshalYAML implements functions.CallGenerator.

Type Spec
type Spec struct {
	yaml.MapSlice
	Type string `yaml:"type"`
}

Spec represents the yaml configuration for a function call generator.

Methods
func (s *Spec) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements yaml.Unmarshaler.

Documentation

Index

Constants

View Source
const LogCallWithContextDescription = `` /* 761-byte string literal not displayed */

LogCallWithContextDescription documents LogCallWithContext.

View Source
const SimpleLogCallDescription = `` /* 133-byte string literal not displayed */

SimpleLogCallDescription documents SimpleLogCall.

Variables

This section is empty.

Functions

func CallGenerators

func CallGenerators() []string

CallGenerators lists all of the available CallGenerators.

func RegisterCallGenerator

func RegisterCallGenerator(callGenerator CallGenerator)

RegisterCallGenerator registers a new function call generator.

Types

type CallGenerator

type CallGenerator interface {
	// UnmarshalYAML unmarshals the annotator's yaml configuration.
	UnmarshalYAML(buf []byte) error
	// Import returns the import path for the function to be generated by
	// Generate.
	Import() string
	// Generate creates the appropriate call code and import path for
	// the function to be used as an annotation.
	Generate(*token.FileSet, *types.Func, *ast.FuncDecl) (string, error)
	// Describe returns a description for the function annotation.
	Describe() string
}

CallGenerator represents the ability to generate code for a function call using arguments taken from a function call signature.

func Lookup

func Lookup(typeName string) CallGenerator

Lookup returns the CallGenerator, if any, with the specified type.

type EssentialOptions

type EssentialOptions struct {
	Type         string `yaml:"type" annotator:"name of annotator type."`
	ImportPath   string `yaml:"importPath" annotator:"import path for the logging function."`
	FunctionName string `yaml:"functionName" annotator:"name of the function to be invoked."`
}

EssentialOptions represents the configuration options required for all function generators.

type LogCallWithContext

type LogCallWithContext struct {
	EssentialOptions `yaml:",inline"`
	ContextType      string `yaml:"contextType" annotator:"type for the context parameter and result."`
}

LogCallWithContext represents a function call generator for a logging call with the following signature:

func (ctx <contextType>, functionName, callerLocation, format string, arguments ...interface{}) func(ctx <contextType>, format string, namedResults ...interface{})

See LogCallWithContextDescription for a complete description.

func (*LogCallWithContext) Describe

func (lc *LogCallWithContext) Describe() string

Describe implements functions.CallGenerator.

func (*LogCallWithContext) Generate

func (lc *LogCallWithContext) Generate(fset *token.FileSet, fn *types.Func, decl *ast.FuncDecl) (string, error)

func (*LogCallWithContext) Import

func (lc *LogCallWithContext) Import() string

Import implements functions.CallGenerator.

func (*LogCallWithContext) UnmarshalYAML

func (lc *LogCallWithContext) UnmarshalYAML(buf []byte) error

UnmarshalYAML implements functions.CallGenerator.

type SimpleLogCall

type SimpleLogCall struct {
	EssentialOptions `yaml:",inline"`
	ContextType      string `yaml:"contextType" annotator:"type for the context parameter and result."`
}

SimpleLogCall represents a function call generator for a logging call with the same signature as log.Callf and fmt.Printf.

func (*SimpleLogCall) Describe

func (sl *SimpleLogCall) Describe() string

Describe implements functions.CallGenerator.

func (*SimpleLogCall) Generate

func (sl *SimpleLogCall) Generate(fset *token.FileSet, fn *types.Func, decl *ast.FuncDecl) (string, error)

func (*SimpleLogCall) Import

func (sl *SimpleLogCall) Import() string

Import implements functions.CallGenerator.

func (*SimpleLogCall) UnmarshalYAML

func (sl *SimpleLogCall) UnmarshalYAML(buf []byte) error

UnmarshalYAML implements functions.CallGenerator.

type Spec

type Spec struct {
	yaml.MapSlice
	Type string `yaml:"type"`
}

Spec represents the yaml configuration for a function call generator.

func (*Spec) UnmarshalYAML

func (s *Spec) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements yaml.Unmarshaler.

Jump to

Keyboard shortcuts

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