binding

package module
v0.0.0-...-5b080f2 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

README

binding

A model binding written in Golang

Go Report Card GoDoc

quickstart

package main

import (
	"fmt"
	"github.com/billcoding/binding"
)

func main() {
	type model struct {
		ID string `binding:"name(id) default(100) trim(T) prefix(PREFIX-) suffix(-SUFFIX)"`
	}
	m := model{}
	binding.New(&m).BindMap(map[string]interface{}{"ID": "hello world"})
	fmt.Println(m.ID)
	// outputs: PREFIX-100-SUFFIX
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Header Type
	Header = &Type{"header"}
	// Param Type
	Param = &Type{"param"}
)

Functions

This section is empty.

Types

type Binding

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

Binding struct

func New

func New(structPtr interface{}) *Binding

New return new Binding

func NewWithType

func NewWithType(structPtr interface{}, typ *Type) *Binding

NewWithType return new Binding

func (*Binding) BindMap

func (b *Binding) BindMap(dataMap map[string]interface{})

BindMap start bind from data map

func (*Binding) BindReq

func (b *Binding) BindReq(req *http.Request)

BindReq start bind from Request

type Func

type Func interface {
	// Bind call
	Bind(inValue reflect.Value) (outValue reflect.Value)
}

Func interface

func DefaultFunc

func DefaultFunc(defaultVal string) Func

DefaultFunc method

func JoinFunc

func JoinFunc(join bool, sp string) Func

JoinFunc method

func PrefixFunc

func PrefixFunc(prefix string) Func

PrefixFunc method

func SplitFunc

func SplitFunc(split bool, sp string) Func

SplitFunc method

func SuffixFunc

func SuffixFunc(suffix string) Func

SuffixFunc method

func TrimFunc

func TrimFunc(trim bool, sp string) Func

TrimFunc method

type Item

type Item struct {
	Name    string `alias:"name"`
	Default string `alias:"default"`
	Split   bool   `alias:"split"`
	SplitSp string `alias:"split_sp"`
	Trim    bool   `alias:"trim"`
	TrimSp  string `alias:"trim_sp"`
	Join    bool   `alias:"join"`
	JoinSp  string `alias:"join_sp"`
	Prefix  string `alias:"prefix"`
	Suffix  string `alias:"suffix"`
}

Item struct

func (*Item) Bind

func (i *Item) Bind(field *reflect.StructField, value reflect.Value, dataMap map[string]interface{})

Bind call

func (*Item) String

func (i *Item) String() string

String

type Type

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

Type struct

Jump to

Keyboard shortcuts

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