codegen

package
v0.25.1 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2025 License: Apache-2.0 Imports: 22 Imported by: 1

Documentation

Overview

Package codegen contains functions and types used by the weaver_gen.go files generated by "weaver generate". The APIs in this package are not suitable for direct use by Service Weaver applications.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CatchPanics

func CatchPanics(r interface{}) error

CatchPanics recovers from panic() calls that occur during encoding, decoding, and RPC execution.

func ComponentConfigValidator

func ComponentConfigValidator(path, cfg string) error

ComponentConfigValidator checks that cfg is a valid configuration for the component type whose fully qualified name is given by path.

TODO(mwhittaker): Move out of codegen package? It's not used by the generated code.

func ExtractEdges

func ExtractEdges(data []byte) [][2]string

ExtractEdges returns the edges corresponding to MakeEdgeString() results that occur in data.

func MakeEdgeString

func MakeEdgeString(src, dst string) string

MakeEdgeString returns a string that should be emitted into generated code to represent an edge from src to dst.

func MakeListenersString

func MakeListenersString(component string, listeners []string) string

MakeListenersString returns a string that should be emitted into generated code to represent the set of listeners associated with a given component.

func Register

func Register(reg Registration)

Register registers a Service Weaver component.

func RegisterSerializable

func RegisterSerializable[T AutoMarshal]()

RegisterSerializable records type T as serializable. This is needed to instantiate the appropriate concrete type when an interface is sent over the wire (currently only used for AutoMarshal errors returned from remote method calls). The registration is automatically done by generated code for custom error structs that embed weaver.AutoMarshal.

Types

type AutoMarshal

type AutoMarshal interface {
	WeaverMarshal(enc *Encoder)
	WeaverUnmarshal(dec *Decoder)
}

AutoMarshal is the interface implemented by structs with weaver.AutoMarshal declarations.

type CallEdge

type CallEdge struct {
	Caller