derive

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: 2 Imported by: 0

README

Package cloudeng.io/go/derive

CircleCI Go Report Card

import cloudeng.io/go/derive

Package derive provides support for deriving go code from existing code. Functions are provided for obtaining the text representations of existing go types and function signatures that can be used when generating annotations.

Constants

ContextType
ContextType = "context.Context"

ContextType is the standard go context type.

Functions

Func ArgsForParams
func ArgsForParams(signature *types.Signature, ignoreAtPosition ...int) (format string, arguments []string)

ArgsForParams returns the format and arguments to use to log the function's arguments. The option ignoreAtPosition arguments specify that those positions should be ignored altogether. This is useful for handling context.Context like arguments which need often need to be handled separately.

Func ArgsForResults
func ArgsForResults(signature *types.Signature) (format string, arguments []string)

ArgsForResults returns the format and arguments to use to log the function's results.

Func FormatForVar
func FormatForVar(v *types.Var) (string, string)

FormatForVar determines an appropriate format spec and argument for a single function argument or result. The format spec is intended to be passed to a fmt style logging function. It takes care to ensure that the log output is bounded as follows:

1. strings and types that implement stringer are printed as %.10s
2. slices and maps have only their length printed
3. errors are printed as %v with no other restrictions
4. runes are printed as %c, bytes as %02x and pointers are as %02x
5. for all other types, only the name of the variable is printed
Func HasContext
func HasContext(signature *types.Signature) (string, bool)

HasContext returns true and the name of the first parameter to the function if that first parameter is context.Context.

Func HasCustomContext
func HasCustomContext(signature *types.Signature, customContext string) (string, bool)

HasCustomContext returns true and the name of the first parameter to the function if that first parameter is the specified customContext.

Func ParamAt
func ParamAt(signature *types.Signature, pos int) (varName, typeName string, ok bool)

ParamAt returns the name and type of the parameter at pos. It returns false if no such parameter exists.

Documentation

Overview

Package derive provides support for deriving go code from existing code. Functions are provided for obtaining the text representations of existing go types and function signatures that can be used when generating annotations.

Index

Constants

View Source
const ContextType = "context.Context"

ContextType is the standard go context type.

Variables

This section is empty.

Functions

func ArgsForParams

func ArgsForParams(signature *types.Signature, ignoreAtPosition ...int) (format string, arguments []string)

ArgsForParams returns the format and arguments to use to log the function's arguments. The option ignoreAtPosition arguments specify that those positions should be ignored altogether. This is useful for handling context.Context like arguments which need often need to be handled separately.

func ArgsForResults

func ArgsForResults(signature *types.Signature) (format string, arguments []string)

ArgsForResults returns the format and arguments to use to log the function's results.

func FormatForVar

func FormatForVar(v *types.Var) (string, string)

FormatForVar determines an appropriate format spec and argument for a single function argument or result. The format spec is intended to be passed to a fmt style logging function. It takes care to ensure that the log output is bounded as follows:

  1. strings and types that implement stringer are printed as %.10s
  2. slices and maps have only their length printed
  3. errors are printed as %v with no other restrictions
  4. runes are printed as %c, bytes as %02x and pointers are as %02x
  5. for all other types, only the name of the variable is printed

func HasContext

func HasContext(signature *types.Signature) (string, bool)

HasContext returns true and the name of the first parameter to the function if that first parameter is context.Context.

func HasCustomContext

func HasCustomContext(signature *types.Signature, customContext string) (string, bool)

HasCustomContext returns true and the name of the first parameter to the function if that first parameter is the specified customContext.

func ParamAt

func ParamAt(signature *types.Signature, pos int) (varName, typeName string, ok bool)

ParamAt returns the name and type of the parameter at pos. It returns false if no such parameter exists.

Types

This section is empty.

Jump to

Keyboard shortcuts

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