Giter VIP home page Giter VIP logo

plz.codegen's Introduction

wombat

Sourcegraph GoDoc Build Status codecov rcard License Gitter chat

binding & validation & functional goodies.

implements api defined in v2pro/plz/util package

Example

//go:generate go install github.com/v2pro/wombat/cmd/wombat-codegen
//go:generate $GOPATH/bin/wombat-codegen -pkg github.com/v2pro/wombat/example
func init() {
	generic.Declare(func() {
		plz.Max(int(0))
		plz.Max(float64(0))
		plz.Max(model.User{}, "Score")
	})
}

func Demo_max_min(t *testing.T) {
	should := require.New(t)
	should.Equal(3, plz.Max(1, 3, 2))
	should.Equal(float64(3), plz.Max(1.0, 3.0, 2.0))
	should.Equal(model.User{3}, plz.Max(
		model.User{1}, model.User{3}, model.User{2},
		"Score"))
}

replace github.com/v2pro/wombat/example with your package name.

you need call go generate before compile

plz.codegen's People

Contributors

taowen avatar elvizlai avatar

Stargazers

 avatar Rainy Chan avatar xiazemin avatar  avatar nlimpid avatar ik5 avatar  avatar  avatar Lee avatar  avatar  avatar GAO Wei avatar catplanet007 avatar Koichi Shiraishi avatar  avatar Tang Xinyao avatar Chen Kai avatar  avatar  avatar Halo Master avatar  avatar Hou 42 avatar Larry Xu avatar hbc avatar 老男孩 avatar Michael.谢 avatar luwei avatar chyroc avatar dxsoft avatar Neo Liu avatar oskca avatar Chengjun Xie avatar  avatar  avatar jacky liu avatar Hardy avatar  avatar Christoph Berger avatar Gronpipmaster avatar Roman Heinrich avatar  avatar 一二三四 avatar Xiaofan Hu avatar Xargin avatar Marvin Liao avatar LukeB42 avatar

Watchers

Halo Master avatar  avatar James Cloos avatar  avatar  avatar  avatar

plz.codegen's Issues

Benchmark Max of int performance

[]int 10000000 135 ns/op 0 B/op 0 allocs/op
[]interface{} manulally 10000000 221 ns/op 8 B/op 1 allocs/op
[]interface{} reflect.Value 2000000 875 ns/op 8 B/op 1 allocs/op
[]interface{} accessor 5000000 256 ns/op 8 B/op 1 allocs/op

min/max

int int8 float64
max Y Y
min

copy native objects

simple value

  • int
  • int8
  • int16
  • int32
  • int64
  • uint
  • uint8
  • uint16
  • uint32
  • uint64
  • float32
  • float64
  • string
  • bool

one level

  • int => *int
  • *int => int
  • [3]int => [3]int
  • [3]int => []int
  • map[string]int => map[string]int
  • map[string]int => struct
  • []int => [3]int
  • []int => []int
  • strut => map[string]int
  • struct => struct

two levels

  • slice + array
  • slice + map
  • [][]int => [][]int
  • slice + struct
  • array + array
  • array + map
  • array + slice
  • array + struct
  • map + array
  • map + map
  • map + slice
  • map + struct
  • struct + (array, map, slice, struct)

existing value

  • int => *int
  • []int => []*int
  • [3]int => [3]*int
  • struct (int) => struct (*int)
  • map[string]int => map[string]*int
  • int => *interface{} (*int)
  • []int => *interface{} ([]*int)

new value

  • int => *int
  • [3]int => *[3]int
  • struct => *struct
  • []int => []int
  • map[string]int => map[string]int

nil

  • int => (*int)(nil)
  • (*int)(nil) => int
  • (**int)(nil) => int
  • &(*int)(nil) => int
  • (*int)(nil) => *int
  • (**int)(nil) => *int
  • &(*int)(nil) => *int
  • []int => []int
  • map[string]int => map[string]int

empty interface

  • *interface{} => int
  • *interface{} => []int
  • int => *interface{}
  • []int => *interface{}
  • []interface{} => []int
  • []int => []interface{}
  • []interface{} => []interface{}
  • map[string]interface{} => map[string]int
  • map[string]int => map[string]interface{}
  • map[string]interface{} => map[string]interface{}

copy json

simple value

  • int
  • int8
  • int16
  • int32
  • int64
  • uint
  • uint8
  • uint16
  • uint32
  • uint64
  • float32
  • float64
  • string
  • bool

one level

  • slice + int
  • array + int
  • map + (string, int)
  • struct + *

two levels

  • slice + array
  • slice + map
  • slice + slice
  • slice + struct
  • array + array
  • array + map
  • array + slice
  • array + struct
  • map + array
  • map + map
  • map + slice
  • map + struct
  • struct + (array, map, slice, struct)

existing value

  • slice + int
  • array + int
  • map + (string, int)
  • struct

new value

nil

  • ptr int
  • ptr ptr int
  • slice int
  • slice ptr int
  • array
  • map
  • struct

empty interface

field tag

  • rename

extra

  • struct
  • [2]int

invalid

  • int
  • int via interface{}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.