function

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2025 License: MIT Imports: 21 Imported by: 4

README

go-function

Wrapping Go functions as HTTP handlers and CLI commands

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CatchHTTPHandlerPanics = true
	PrettyPrint            = true
	PrettyPrintIndent      = "  "
)
View Source
var (
	StringScanners = NewTypeStringScanners(StringScannerFunc(DefaultScanString))

	ArgNameTag        = "arg"
	ArgDescriptionTag = "desc"

	// TimeFormats used in that order to try parse time strings.
	// If a time format has not time zone part,
	// then the date is returned in the local time zone.
	TimeFormats = []string{
		time.RFC3339Nano,
		time.RFC3339,
		time.DateOnly + " 15:04:05.999999999 -0700 MST",
		time.DateTime,
		time.DateOnly + " 15:04",
		time.DateOnly + "T15:04",
		time.DateOnly,
	}
)
View Source
var (
	// ErrTypeNotSupported indicates that a type is not supported
	ErrTypeNotSupported = errors.New("type not supported")

	// HandleErrorHTTP will handle a non nil error by writing it to the response.
	// The default is to use github.com/ungerik/go-httpx/httperr.DefaultHandler.
	HandleErrorHTTP = func(err error, response http.ResponseWriter, request *http.Request) {
		if err != nil {
			httperr.DefaultHandler.HandleError(err, response, request)
		}
	}
)
View Source
var RespondNothing respondNothing

Functions

func CallFunctionWithJSONArgs

func CallFunctionWithJSONArgs(ctx context.Context, f Wrapper, jsonObject []byte) (results []any, err error)

func DefaultScanString

func DefaultScanString(sourceStr string, destPtr any) (err error)

func DetectContentType

func DetectContentType(data []byte) string

DetectContentType tries to detect the MIME content-type of data, or returns "application/octet-stream" if none could be identified.

func HTTPHandler

func HTTPHandler(getArgs HTTPRequestArgsGetter, function CallWithNamedStringsWrapper, resultsWriter HTTPResultsWriter, errHandlers ...httperr.Handler) http.HandlerFunc

func HTTPHandlerNoWrapper

func HTTPHandlerNoWrapper(function func(context.Context) ([]byte, error), resultsWriter HTTPResultsWriter, errHandlers ...httperr.Handler) http.HandlerFunc

HTTPHandlerNoWrapper returns an http.Handler for a function without a wrapper of type func(context.Context) ([]byte, error) that returns response bytes.

func HTTPRequestBodyJSONFieldsAsArgs

func HTTPRequestBodyJSONFieldsAsArgs(request *http.Request) (map[string]string, error)

func HTTPRequestMultipartFormArgs

func HTTPRequestMultipartFormArgs(request *http.Request) (map[string]string, error)

HTTPRequestMultipartFormArgs returns the multipart form values of the request as string map. If a form field has multiple values, they are joined with ";".

func HTTPRequestQueryArgs

func HTTPRequestQueryArgs(request *http.Request) (map[string]string, error)

HTTPRequestQueryArgs returns the query params of the request as string map. If a query param has multiple values, they are joined with ";".

func ScanString

func ScanString(sourceStr string, destPtr any) error

ScanString uses the configured DefaultStringScanner to scan sourceStr to destPtr.

func ScanStrings

func ScanStrings(sourceStrings []string, destPtrs ...any) error

ScanStrings uses the configured DefaultStringScanner to scan sourceStrings to destPtrs. If the number of sourceStrings and destPtrs is not identical then only the lower number of either will be scanned.

Types

type CallWithJSONWrapper

type CallWithJSONWrapper interface {
	CallWithJSON(ctx context.Context, argsJSON []byte) (results []any, err error)
}

func CallWithJSONWrapperTODO

func CallWithJSONWrapperTODO(function any) CallWithJSONWrapper

type CallWithJSONWrapperFunc

type CallWithJSONWrapperFunc func(ctx context.Context, argsJSON []byte) (results []any, err error)

func (CallWithJSONWrapperFunc) CallWithJSON

func (f CallWithJSONWrapperFunc) CallWithJSON(ctx context.Context, argsJSON []byte) (results []any, err error)

type CallWithNamedStringsWrapper

type CallWithNamedStringsWrapper interface {
	CallWithNamedStrings(ctx context.Context, args map[string]string) (results []any, err error)
}

func CallWithNamedStringsWrapperTODO

func CallWithNamedStringsWrapperTODO(function any) CallWithNamedStringsWrapper

type CallWithNamedStringsWrapperFunc

type CallWithNamedStringsWrapperFunc func(ctx context.Context, args map[string]string) (results []any, err error)

func (CallWithNamedStringsWrapperFunc) CallWithNamedStrings

func (f CallWithNamedStringsWrapperFunc) CallWithNamedStrings(ctx context.Context, args map[string]string) (results []any, err error)

type CallWithStringsWrapper

type CallWithStringsWrapper interface {
	CallWithStrings(ctx context.Context, args ...string) (results []any, err error)
}

func CallWithStringsWrapperTODO

func CallWithStringsWrapperTODO(function any) CallWithStringsWrapper

type CallWithStringsWrapperFunc

type CallWithStringsWrapperFunc func(ctx context.Context, args ...string) (results []any, err error)

func (CallWithStringsWrapperFunc) CallWithStrings

func (f CallWithStringsWrapperFunc) CallWithStrings(ctx context.Context, args ...string) (results []any, err error)

type CallWrapper

type CallWrapper interface {
	Call(ctx context.Context, args []any) (results []any, err error)
}

func CallWrapperTODO

func CallWrapperTODO(function any) CallWrapper

type CallWrapperFunc

type CallWrapperFunc func(ctx context.Context, args []any) (results []any, err error)

func (CallWrapperFunc) Call

func (f CallWrapperFunc) Call(ctx context.Context, args []any) (results []any, err error)

type Description

type Description interface {
	Name() string
	String() string

	NumArgs() int
	ContextArg() bool
	NumResults() int
	ErrorResult() bool

	ArgNames() []string
	ArgDescriptions() []string
	ArgTypes() []reflect.Type
	ResultTypes() []reflect.Type
}

func ReflectDescription

func ReflectDescription(name string, f any) (Description, error)

type ErrParseArgJSON

type ErrParseArgJSON struct {
	Err  error
	Func fmt.Stringer
	Arg  string
}

func NewErrParseArgJSON

func NewErrParseArgJSON(err error, f fmt.Stringer, arg string) ErrParseArgJSON

func (ErrParseArgJSON) Error

func (e ErrParseArgJSON) Error() string

func (ErrParseArgJSON) Unwrap

func (e ErrParseArgJSON) Unwrap() error

type ErrParseArgString

type ErrParseArgString struct {
	Err      error
	Func     fmt.Stringer
	ArgName  string
	ArgValue string
}

func NewErrParseArgString

func NewErrParseArgString(err error, f fmt.Stringer, argName, argValue string) ErrParseArgString

func (ErrParseArgString) Error

func (e ErrParseArgString) Error() string

func (ErrParseArgString) Unwrap

func (e ErrParseArgString) Unwrap() error

type ErrParseArgsJSON

type ErrParseArgsJSON struct {
	Err  error
	Func fmt.Stringer
	JSON string
}

func NewErrParseArgsJSON

func NewErrParseArgsJSON(err error, f fmt.Stringer, argsJSON []byte) ErrParseArgsJSON

func (ErrParseArgsJSON) Error

func (e ErrParseArgsJSON) Error() string

func (ErrParseArgsJSON) Unwrap

func (e ErrParseArgsJSON) Unwrap() error

type ErrorFuncWrapper added in v0.2.0

type ErrorFuncWrapper func() error

ErrorFuncWrapper returns a Wrapper for a function call without arguments and with one error result.

func (ErrorFuncWrapper) ArgDescriptions added in v0.2.0

func (ErrorFuncWrapper) ArgDescriptions() []string

func (ErrorFuncWrapper) ArgNames added in v0.2.0

func (ErrorFuncWrapper) ArgNames() []string

func (ErrorFuncWrapper) ArgTypes added in v0.2.0

func (ErrorFuncWrapper) ArgTypes() []reflect.Type

func (ErrorFuncWrapper) Call added in v0.2.0

func (f ErrorFuncWrapper) Call(context.Context, []any) ([]any, error)

func (ErrorFuncWrapper) CallWithJSON added in v0.2.0

func (f ErrorFuncWrapper) CallWithJSON(context.Context, []byte) (results []any, err error)

func (ErrorFuncWrapper) CallWithNamedStrings added in v0.2.0

func (f ErrorFuncWrapper) CallWithNamedStrings(context.Context, map[string]string) ([]any, error)

func (ErrorFuncWrapper) CallWithStrings added in v0.2.0

func (f ErrorFuncWrapper) CallWithStrings(context.Context, ...string) ([]any, error)

func (ErrorFuncWrapper) ContextArg added in v0.2.0

func (ErrorFuncWrapper) ContextArg() bool

func (ErrorFuncWrapper) ErrorResult added in v0.2.0

func (ErrorFuncWrapper) ErrorResult() bool

func (ErrorFuncWrapper) Name added in v0.2.0

func (ErrorFuncWrapper) Name() string

func (ErrorFuncWrapper) NumArgs added in v0.2.0

func (ErrorFuncWrapper) NumArgs() int

func (ErrorFuncWrapper) NumResults added in v0.2.0

func (ErrorFuncWrapper) NumResults() int

func (ErrorFuncWrapper) ResultTypes added in v0.2.0

func (ErrorFuncWrapper) ResultTypes() []reflect.Type

func (ErrorFuncWrapper) String added in v0.2.0

func (ErrorFuncWrapper) String() string

type HTTPRequestArgsGetter

type HTTPRequestArgsGetter func(*http.Request) (map[string]string, error)

func HTTPRequestArg

func HTTPRequestArg(name, value string) HTTPRequestArgsGetter

func HTTPRequestArgs

func HTTPRequestArgs(args map[string]string) HTTPRequestArgsGetter

func HTTPRequestBodyAsArg

func HTTPRequestBodyAsArg(name string) HTTPRequestArgsGetter

func HTTPRequestQueryArg

func HTTPRequestQueryArg(name string) HTTPRequestArgsGetter

func HTTPRequestQueryAsArg

func HTTPRequestQueryAsArg(queryKey, name string) HTTPRequestArgsGetter

func MergeHTTPRequestArgs

func MergeHTTPRequestArgs(getters ...HTTPRequestArgsGetter) HTTPRequestArgsGetter

type HTTPResultsWriter

type HTTPResultsWriter interface {
	// WriteResults writes the results and optionally the resultErr to the response.
	// If the method does not handle the resultErr then it should return it
	// so it can be handled by the next writer in the chain.
	WriteResults(results []any, resultErr error, response http.ResponseWriter, request *http.Request) error
}

HTTPResultsWriter implementations write the results of a function call to an HTTP response.

func RespondContentType

func RespondContentType(contentType string) HTTPResultsWriter

type HTTPResultsWriterFunc

type HTTPResultsWriterFunc func(results []any, resultErr error, response http.ResponseWriter, request *http.Request) error
var RespondDetectContentType HTTPResultsWriterFunc = func(results []any, resultErr error, response http.ResponseWriter, request *http.Request) error {

	if resultErr != nil || request.Context().Err() != nil {
		return resultErr
	}
	if len(results) != 1 {
		return fmt.Errorf("RespondDetectContentType needs 1 result, got %d", len(results))
	}
	data, ok := results[0].([]byte)
	if !ok {
		return fmt.Errorf("RespondDetectContentType needs []byte result, got %T", results[0])
	}

	response.Header().Add("Content-Type", DetectContentType(data))
	_, err := response.Write(data)
	return err
}
var RespondHTML HTTPResultsWriterFunc = func(results []any, resultErr error, response http.ResponseWriter, request *http.Request) error {

	if resultErr != nil || request.Context().Err() != nil {
		return resultErr
	}
	var buf bytes.Buffer
	for _, result := range results {
		if b, ok := result.([]byte); ok {
			buf.Write(b)
		} else {
			fmt.Fprint(&buf, result)
		}
	}
	response.Header().Add("Content-Type", contenttype.HTML)
	_, err := response.Write(buf.Bytes())
	return err
}
var RespondJSON HTTPResultsWriterFunc = func(results []any, resultErr error, response http.ResponseWriter, request *http.Request) error {

	if resultErr != nil || request.Context().Err() != nil {
		return resultErr
	}

	if len(results) == 0 {
		return nil
	}

	var r any
	if len(results) == 1 {

		r = results[0]
	} else {

		r = results
	}
	j, err := encodeJSON(r)
	if err != nil {
		return err
	}
	response.Header().Set("Content-Type", contenttype.JSON)
	_, err = response.Write(j)
	return err
}

RespondJSON writes the results of a function call as a JSON to the response. If the function returns one non-error result then it is marshalled as is. If the function returns multiple results then they are marshalled as a JSON array. If the function returns an resultErr then it is returned by this method, so it can be handled by the next writer in the chain. Any resultErr is not handled and will be returned by this method.

var RespondPlaintext HTTPResultsWriterFunc = func(results []any, resultErr error, response http.ResponseWriter, request *http.Request) error {

	if resultErr != nil || request.Context().Err() != nil {
		return resultErr
	}
	var buf bytes.Buffer
	fmt.Fprint(&buf, results...)
	response.Header().Add("Content-Type", contenttype.PlainText)
	_, err := response.Write(buf.Bytes())
	return err
}

RespondPlaintext writes the results of a function call as a plaintext to the response using fmt.Fprint to format the results. Spaces are added between results when neither is a string. Any resultErr is not handled and will be returned by this method.

var RespondXML HTTPResultsWriterFunc = func(results []any, resultErr error, response http.ResponseWriter, request *http.Request) error {

	if resultErr != nil || request.Context().Err() != nil {
		return resultErr
	}
	var buf []byte
	for i, result := range results {
		if i > 0 {
			buf = append(buf, '\n')
		}
		b, err := encodeXML(result)
		if err != nil {
			return err
		}
		buf = append(buf, b...)
	}
	response.Header().Set("Content-Type", contenttype.XML)
	_, err := response.Write(buf)
	return err
}

func RespondBinary

func RespondBinary(contentType string) HTTPResultsWriterFunc

RespondBinary responds with contentType using the binary data from results of type []byte, string, or io.Reader. Any resultErr is not handled and will be returned by this method.

func RespondJSONObject

func RespondJSONObject(resultKeys ...string) HTTPResultsWriterFunc

RespondJSONObject writes the results of a function call as a JSON object to the response. The resultKeys are the keys of the JSON object, naming the function results in order.

If the last result is an error and the resultKeys don't have a key for it then the error is returned unhandled if not nil. If there is a result key for the error then the error is marshalled as JSON string and not returned.

An error is returned if the number of results does not match the number of resultKeys or number of resultKeys minus one if the last result is an error.

func (HTTPResultsWriterFunc) WriteResults

func (f HTTPResultsWriterFunc) WriteResults(results []any, resultErr error, response http.ResponseWriter, request *http.Request) error

type JSONArgsFunc

type JSONArgsFunc func(ctx context.Context, jsonObject []byte) error

func NewJSONArgsFunc

func NewJSONArgsFunc(f Wrapper, resultsHandlers ...ResultsHandler) JSONArgsFunc

type Logger

type Logger interface {
	Printf(format string, args ...any)
}

Logger interface

type NamedStringArgsFunc

type NamedStringArgsFunc func(ctx context.Context, args map[string]string) error

func NewNamedStringArgsFunc

func NewNamedStringArgsFunc(f CallWithNamedStringsWrapper, resultsHandlers ...ResultsHandler) NamedStringArgsFunc

type PrintlnText

type PrintlnText string

PrintlnText prints a fixed string if a command returns without an error

func (PrintlnText) HandleResults

func (t PrintlnText) HandleResults(ctx context.Context, results []any, resultErr error) error

type RespondRedirect

type RespondRedirect string

RespondRedirect implements HTTPResultsWriter and http.Handler with for a redirect URL string. The redirect will be done with HTTP status code 302: Found.

func (RespondRedirect) ServeHTTP

func (re RespondRedirect) ServeHTTP(response http.ResponseWriter, request *http.Request)

func (RespondRedirect) WriteResults

func (re RespondRedirect) WriteResults(results []any, resultErr error, response http.ResponseWriter, request *http.Request) error

type RespondRedirectFunc

type RespondRedirectFunc func(request *http.Request) (url string, err error)

RespondRedirectFunc implements HTTPResultsWriter and http.Handler with a function that returns the redirect URL. The redirect will be done with HTTP status code 302: Found.

func (RespondRedirectFunc) ServeHTTP

func (f RespondRedirectFunc) ServeHTTP(response http.ResponseWriter, request *http.Request)

func (RespondRedirectFunc) WriteResults

func (f RespondRedirectFunc) WriteResults(results []any, resultErr error, response http.ResponseWriter, request *http.Request) error

type RespondStaticHTML

type RespondStaticHTML string

func (RespondStaticHTML) ServeHTTP

func (html RespondStaticHTML) ServeHTTP(response http.ResponseWriter, _ *http.Request)

func (RespondStaticHTML) WriteResults

func (html RespondStaticHTML) WriteResults(results []any, resultErr error, response http.ResponseWriter, request *http.Request) error

type RespondStaticJSON

type RespondStaticJSON string

func (RespondStaticJSON) ServeHTTP

func (json RespondStaticJSON) ServeHTTP(response http.ResponseWriter, _ *http.Request)

func (RespondStaticJSON) WriteResults

func (json RespondStaticJSON) WriteResults(results []any, resultErr error, response http.ResponseWriter, request *http.Request) error

type RespondStaticPlaintext

type RespondStaticPlaintext string

func (RespondStaticPlaintext) ServeHTTP

func (text RespondStaticPlaintext) ServeHTTP(response http.ResponseWriter, _ *http.Request)

func (RespondStaticPlaintext) WriteResults

func (text RespondStaticPlaintext) WriteResults(results []any, resultErr error, response http.ResponseWriter, request *http.Request) error

type RespondStaticXML

type RespondStaticXML string

func (RespondStaticXML) ServeHTTP

func (xml RespondStaticXML) ServeHTTP(response http.ResponseWriter, _ *http.Request)

func (RespondStaticXML) WriteResults

func (xml RespondStaticXML) WriteResults(results []any, resultErr error, response http.ResponseWriter, request *http.Request) error

type ResultsHandler

type ResultsHandler interface {
	HandleResults(ctx context.Context, results []any, resultErr error) error
}

type ResultsHandlerFunc

type ResultsHandlerFunc func(ctx context.Context, results []any, resultErr error) error
var PrintStructSliceAsTable ResultsHandlerFunc = func(ctx context.Context, results []any, resultErr error) error {
	if resultErr != nil {
		return resultErr
	}
	if len(results) == 0 {
		return nil
	}
	for i, result := range results {

		resultType := reflect.TypeOf(result)
		if resultType.Kind() != reflect.Slice && resultType.Kind() != reflect.Array {
			return fmt.Errorf("expected slice or array, got %T for result %d", result, i)
		}
		if resultType.Elem().Kind() != reflect.Struct && resultType.Elem().Kind() != reflect.Ptr {
			return fmt.Errorf("expected slice/array of structs or struct pointers, got %T for result %d", result, i)
		}
		isPtr := resultType.Elem().Kind() == reflect.Ptr
		structType := resultType.Elem()
		if isPtr {
			structType = structType.Elem()
		}
		var header []string
		for col := 0; col < structType.NumField(); col++ {
			header = append(header, structType.Field(col).Name)
		}
		rows := [][]string{header}

		sliceVal := reflect.ValueOf(result)
		for row := 0; row < sliceVal.Len(); row++ {
			structVal := sliceVal.Index(row)
			if isPtr {
				if structVal.IsNil() {
					continue
				}
				structVal = structVal.Elem()
			}
			fieldStrings := make([]string, structType.NumField())
			for col := 0; col < structType.NumField(); col++ {
				fieldStrings[col] = fmt.Sprint(structVal.Field(col).Interface())
			}
			rows = append(rows, fieldStrings)
		}

		colWidths := make([]int, structType.NumField())
		for row := range rows {
			for col := 0; col < structType.NumField() && col < len(rows[row]); col++ {
				numRunes := utf8.RuneCountInString(rows[row][col])
				colWidths[col] = max(colWidths[col], numRunes)
			}
		}

		if i > 0 {
			fmt.Println()
		}
		w := os.Stdout
		var err error
		for _, rowStrs := range rows {
			for col, colWidth := range colWidths {
				switch {
				case col == 0:
					_, err = w.Write([]byte("| "))
				case col < len(colWidths):
					_, err = w.Write([]byte(" | "))
				}
				if err != nil {
					return err
				}
				str := ""
				if col < len(rowStrs) {
					str = rowStrs[col]
				}
				_, err = io.WriteString(w, str)
				if err != nil {
					return err
				}
				strLen := utf8.RuneCountInString(str)
				for i := strLen; i < colWidth; i++ {
					_, err = w.Write([]byte{' '})
					if err != nil {
						return err
					}
				}
			}
			_, err = w.Write([]byte(" |\n"))
			if err != nil {
				return err
			}
		}
	}
	return nil
}

PrintStructSliceAsTable prints a slice of structs or struct pointers as a padded table to os.Stdout using fmt.Sprint to format field values.

var Println ResultsHandlerFunc = func(ctx context.Context, results []any, resultErr error) error {
	if resultErr != nil {
		return resultErr
	}
	err := makeResultsPrintable(results)
	if err != nil {
		return err
	}
	for _, r := range results {
		_, err = fmt.Println(r)
		if err != nil {
			return err
		}
	}
	return nil
}

Println calls fmt.Println for every result

func LogTo

func LogTo(logger Logger) ResultsHandlerFunc

LogTo calls logger.Printf(fmt.Sprintln(results...))

func LogWithPrefixTo

func LogWithPrefixTo(prefix string, logger Logger) ResultsHandlerFunc

LogWithPrefixTo calls logger.Printf(fmt.Sprintln(results...)) with prefix prepended to the results

func PrintTo

func PrintTo(writer io.Writer) ResultsHandlerFunc

PrintTo calls fmt.Fprint on writer with the result values as varidic arguments

func PrintlnTo

func PrintlnTo(writer io.Writer) ResultsHandlerFunc

PrintlnTo calls fmt.Fprintln on writer for every result

func PrintlnWithPrefix

func PrintlnWithPrefix(prefix string) ResultsHandlerFunc

PrintlnWithPrefix calls fmt.Println(prefix, result) for every result value

func PrintlnWithPrefixTo

func PrintlnWithPrefixTo(prefix string, writer io.Writer) ResultsHandlerFunc

PrintlnWithPrefixTo calls fmt.Fprintln(writer, prefix, result) for every result value

func (ResultsHandlerFunc) HandleResults

func (f ResultsHandlerFunc) HandleResults(ctx context.Context, results []any, resultErr error) error

type StringArgsFunc

type StringArgsFunc func(ctx context.Context, args ...string) error

func NewStringArgsFunc

func NewStringArgsFunc(f CallWithStringsWrapper, resultsHandlers ...ResultsHandler) StringArgsFunc

type StringScanner

type StringScanner interface {
	ScanString(sourceStr string, destPtr any) error
}

type StringScannerFunc

type StringScannerFunc func(sourceStr string, destPtr any) error

func (StringScannerFunc) ScanString

func (f StringScannerFunc) ScanString(sourceStr string, destPtr any) error

type TypeStringScanners

type TypeStringScanners struct {
	Types      map[reflect.Type]StringScanner
	Interfaces map[reflect.Type]StringScanner
	Kinds      map[reflect.Kind]StringScanner
	Default    StringScanner
}

func NewTypeStringScanners

func NewTypeStringScanners(defaultScanner StringScanner) *TypeStringScanners

func (*TypeStringScanners) ScanString

func (s *TypeStringScanners) ScanString(sourceStr string, destPtr any) error

func (*TypeStringScanners) WithDefaultScanner

func (s *TypeStringScanners) WithDefaultScanner(scanner StringScanner) *TypeStringScanners

func (*TypeStringScanners) WithInterfaceTypeScanner

func (s *TypeStringScanners) WithInterfaceTypeScanner(destImplsInterface reflect.Type, scanner StringScanner) *TypeStringScanners

func (*TypeStringScanners) WithKindScanner

func (s *TypeStringScanners) WithKindScanner(destKind reflect.Kind, scanner StringScanner) *TypeStringScanners

func (*TypeStringScanners) WithTypeScanner

func (s *TypeStringScanners) WithTypeScanner(destType reflect.Type, scanner StringScanner) *TypeStringScanners

type VoidFuncWrapper added in v0.2.0

type VoidFuncWrapper func()

VoidFuncWrapper returns a Wrapper for a function call without arguments and without results.

func (VoidFuncWrapper) ArgDescriptions added in v0.2.0

func (VoidFuncWrapper) ArgDescriptions() []string

func (VoidFuncWrapper) ArgNames added in v0.2.0

func (VoidFuncWrapper) ArgNames() []string

func (VoidFuncWrapper) ArgTypes added in v0.2.0

func (VoidFuncWrapper) ArgTypes() []reflect.Type

func (VoidFuncWrapper) Call added in v0.2.0

func (f VoidFuncWrapper) Call(context.Context, []any) ([]any, error)

func (VoidFuncWrapper) CallWithJSON added in v0.2.0

func (f VoidFuncWrapper) CallWithJSON(context.Context, []byte) (results []any, err error)

func (VoidFuncWrapper) CallWithNamedStrings added in v0.2.0

func (f VoidFuncWrapper) CallWithNamedStrings(context.Context, map[string]string) ([]any, error)

func (VoidFuncWrapper) CallWithStrings added in v0.2.0

func (f VoidFuncWrapper) CallWithStrings(context.Context, ...string) ([]any, error)

func (VoidFuncWrapper) ContextArg added in v0.2.0

func (VoidFuncWrapper) ContextArg() bool

func (VoidFuncWrapper) ErrorResult added in v0.2.0

func (VoidFuncWrapper) ErrorResult() bool

func (VoidFuncWrapper) Name added in v0.2.0

func (VoidFuncWrapper) Name() string

func (VoidFuncWrapper) NumArgs added in v0.2.0

func (VoidFuncWrapper) NumArgs() int

func (VoidFuncWrapper) NumResults added in v0.2.0

func (VoidFuncWrapper) NumResults() int

func (VoidFuncWrapper) ResultTypes added in v0.2.0

func (VoidFuncWrapper) ResultTypes() []reflect.Type

func (VoidFuncWrapper) String added in v0.2.0

func (VoidFuncWrapper) String() string

type Wrapper

func MustReflectWrapper

func MustReflectWrapper(function any, argNames ...string) Wrapper

MustReflectWrapper calls ReflectWrapper and panics any error.

func ReflectWrapper

func ReflectWrapper(function any, argNames ...string) (Wrapper, error)

ReflectWrapper returns a Wrapper for the passed function using reflection and the passed argNames. The number of passed argNames must match the number of function arguments. Except when the function only has one argument of type context.Context then "ctx" is assumed as argument name in case no name has been passed.

func WrapperTODO

func WrapperTODO(function any) Wrapper

Directories

Path Synopsis
cli module
cmd
htmlform module

Jump to

Keyboard shortcuts

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