protodef

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Package protodef provides functions to make dynamic protobuf messages with the use of the groxypb options in protobuf snippets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadOS

func LoadOS(d *Definer)

LoadOS sets definer to load the OS files, if they were requested in the definition.

Types

type Definer

type Definer struct {
	// contains filtered or unexported fields
}

Definer parses protobuf snippets and builds protobuf messages according to the specified groxy option values.

func NewDefiner

func NewDefiner(opts ...Option) *Definer

NewDefiner returns a new Definer with the given options applied.

func (*Definer) BuildTarget

func (b *Definer) BuildTarget(def string) (Template, error)

BuildTarget seeks the target message in the given protobuf snippet and returns a proto.Message that can be used to respond requests or match requests to.

type Option

type Option func(*Definer)

Option is a functional option for the definer.

func WithFuncs added in v0.5.0

func WithFuncs(funcs template.FuncMap) Option

WithFuncs sets the definer to use the provided functions for templating. Note: function with the name that has been already defined will be overwritten.

type Template added in v0.5.0

type Template interface {
	DataMap(ctx context.Context, bts []byte) (map[string]any, error)
	Matches(ctx context.Context, bts []byte) (bool, error)
	Generate(ctx context.Context, data map[string]any) (proto.Message, error)
}

Template is an interface for generating protobuf messages based on templates.

func BuildMessage

func BuildMessage(def string) (Template, error)

BuildMessage parses the protobuf definition with groxy options and returns a proto.Message that can be used to respond requests or match requests to.

func Static added in v0.5.0

func Static(msg proto.Message) Template

Static is a Template that returns a static protobuf message without any modifications.

Jump to

Keyboard shortcuts

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