handler

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package handler provides a handler interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler interface {
	Parse(string) (any, error) // Used to optimize: pre-parse and cache the tag value.
	Run(ctx any, rootStructValue, fieldValue reflect.Value, fieldType reflect.StructField, arg any) error
}

Handler is an interface to handle the struct field.

func New added in v0.3.0

func New(parse Parser, run Runner) Handler

New returns a new Handler from the parse and run functions.

parse may be nil, but run must not be nil.

type Parser

type Parser func(string) (any, error)

Parser is the function to pre-parse the field tag value.

type Runner

type Runner func(ctx any, root reflect.Value, vf reflect.Value, sf reflect.StructField, arg any) error

Runner is the function to handle the struct field.

func FieldRunner added in v0.3.0

func FieldRunner(f func(reflect.Value, reflect.StructField, any) error) Runner

FieldRunner converts a field value function to Runner.

func SimpleRunner

func SimpleRunner(f func(field reflect.Value, arg any) error) Runner

SimpleRunner converts a simple function to Runner.

func (Runner) Parse

func (f Runner) Parse(s string) (any, error)

Parse implements the interface Handler, which does nothing and returns the original string input as the parsed result.

func (Runner) Run

func (f Runner) Run(ctx any, r, v reflect.Value, t reflect.StructField, arg any) error

Run implements the interface Handler.

Directories

Path Synopsis
Package setdefault provides a handler to set the default of the struct field.
Package setdefault provides a handler to set the default of the struct field.
Package setter provides a handler to set the struct field to a value.
Package setter provides a handler to set the struct field to a value.
Package validate provides a handler to validate the struct field.
Package validate provides a handler to validate the struct field.

Jump to

Keyboard shortcuts

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