kiss

package module
v0.0.0-...-6c31828 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2013 License: MIT Imports: 5 Imported by: 0

README

kiss

version

v0.3

kiss is utils baseon golang reflection

Installation

go get github.com/sdming/kiss

Usage

import "github.com/sdming/kiss"

Example

For more example usage, please see *_test.go or example.go

todo

  1. typ.Field(i) is slow ?
  2. cache reflect.type ?
  3. add config package, base on kson
  4. refactor
  5. remove unexported field

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtdStruct

func ExtdStruct(dest reflect.Value, src Getter)

copy value from src to dest, the dest must be struct

func Extend

func Extend(dest Setter, src Getter)

like jqery extend, copy value from src to dest

func ParseStruct

func ParseStruct(dest reflect.Value, src StrGetter)

copy value from src to dest, struct must be struct

Types

type GetFunc

type GetFunc func(name string) (interface{}, bool)

GetFunc is a func for getting value by name

func (GetFunc) Get

func (f GetFunc) Get(name string) (reflect.Value, bool)

implements get

type Getter

type Getter interface {
	// get field value by name
	Get(name string) (v reflect.Value, ok bool)
}

value getter

type MapValue

type MapValue reflect.Value

MapValue is value of map[string]interface{}

type Setter

type Setter interface {
	// set field value by name
	Set(name string, value reflect.Value) (ok bool)

	// get all fields name
	Fields() []string
}

value setter

type StrGetFunc

type StrGetFunc func(name string) (string, bool)

GetFunc is a func for getting string value by name

func (StrGetFunc) Get

func (f StrGetFunc) Get(name string) (string, bool)

implements get

type StrGetter

type StrGetter interface {
	// get field value by name
	Get(name string) (v string, ok bool)
}

string value getter

type StructValue

type StructValue reflect.Value

StructValue is value of struct

func (StructValue) Fields

func (s StructValue) Fields() []string

Fields() get fields name slice of a struct

func (StructValue) Get

func (s StructValue) Get(name string) (output reflect.Value, ok bool)

Get return field value by name

func (StructValue) Set

func (s StructValue) Set(name string, value reflect.Value) (ok bool)

Set can set field value by name

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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