gogenwrapper

package
v0.0.0-...-eb8ab59 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2025 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type T

type T struct {
	// PackageName defines the package name of the generated Go source file.
	// It must be specified.
	PackageName string

	// StructNameWrapper defines the name of the wrapper struct.
	// For example, if you are wrapping [http.ResponseWriter], then ResponseWriterWrapper is a common choice.
	// It must be specified.
	StructNameWrapper string

	// StructNameInterceptor defines the name of the interceptor struct.
	// For example, if you are wrapping [http.ResponseWriter], then ResponseWriterInterceptor is a common choice.
	// It must be specified.
	StructNameInterceptor string

	// FunctionNameWrap defines the name of the wrap function.
	// It is the main entrypoint to wrap the interface.
	// For example, if you are wrapping [http.ResponseWriter], then WrapResponseWriter is a common choice.
	// It must be specified.
	FunctionNameWrap string

	// FunctionNameUnwrap defines the name of the unwrap function.
	// For example, if you are wrapping [http.ResponseWriter], then UnwrapResponseWriter is a common choice.
	// It must be specified.
	FunctionNameUnwrap string

	// InterfaceNameUnwrap defines the name of the unwrap interface.
	// For example, if you are wrapping [http.ResponseWriter], then ResponseWriterUnwrapper is a common choice.
	// It must be specified.
	InterfaceNameUnwrap string

	// FunctionTypeNamePrefix defines the prefix of the function type for each interface method.
	// For example, if you are wrapping [http.ResponseWriter], then ResponseWriter_ is a common choice.
	// It can be an empty string.
	FunctionTypeNamePrefix string

	// BaseInterface is the base interface.
	// It must be a pointer to the interface.
	// For example, if you are wrapping [http.ResponseWriter], pass in new(http.ResponseWriter).
	BaseInterface any

	// AdditionalInterfaces are the additional interfaces that the wrapped interface may implement.
	// The value must be a pointer to an interface.
	// For example, if you are wrapping [http.ResponseWriter], you need to pass in all possible interfaces
	// that can be implemented by [http.ResponseWriter], like [http.Fluster].
	// It can be unspecified. In this case, the wrapper only implements the base interface.
	AdditionalInterfaces []any
}

T is a wrapper generator for complex interfaces likes http.ResponseWriter and driver.Conn.

func (*T) GenerateGoSourceFile

func (g *T) GenerateGoSourceFile() (code string, err error)

GenerateGoSourceFile generates the Go source file for the wrapper. You are supposed to write it to a file.

func (*T) GenerateGoTestFile

func (g *T) GenerateGoTestFile() (code string, err error)

GenerateGoTestFile generates the Go test file for the wrapper. You are supposed to write it to a file.

Directories

Path Synopsis
internal
nethttp/codegen command

Jump to

Keyboard shortcuts

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