Code Monkey home page Code Monkey logo

retag's Introduction

Retag TravisCI GoDoc Go Report Card codecov

Package retag provides an ability to change tags of structures' fields in runtime without copying of the data. It may be helpful in next cases:

  • Automatic tags generation;
  • Different views of the one data;
  • Fixing of leaky abstractions with minimal boilerplate code when application has layers of abstractions and model is separated from storages and presentation layers.

Please see examples in documentation for details.

Features:

  • No memory allocations (for cached types);
  • Fast converting (lookup in table and pointer creation for cached types);
  • Works with complex and nested types (e.g. map[struct]*struct).

The package requires go1.7+.

Installation

go get github.com/sevlyar/retag

You can use gopkg.in:

go get gopkg.in/sevlyar/retag.v0

Documentation

Please see godoc.org/github.com/sevlyar/retag

retag's People

Contributors

alholm avatar sevlyar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

retag's Issues

error type out of range when use for embed fields

hi
tnx for good package.

when I run this code:

       type Product struct {
		gorm.Model `view:"gorm"`
		Code string `view:"*"`
		Price uint `view:"*"`

	}


	product := &Product{}

	gormProduct := retag.Convert(product, retag.NewView("json", "gorm"))

	fmt.Println(gormProduct, reflect.TypeOf(gormProduct))

output error is:

runtime: typeOff 0xffffffffffffffed base 0xc4200ac700 not in ranges:
	types 0x66f000 etypes 0x72154c
fatal error: runtime: type offset base pointer out of range

goroutine 1 [running]:
runtime.throw(0x705437, 0x2e)
	/usr/local/go/src/runtime/panic.go:596 +0x95 fp=0xc42015d160 sp=0xc42015d140
runtime.resolveTypeOff(0xc4200ac700, 0xffffffed, 0x671d87)
	/usr/local/go/src/runtime/type.go:223 +0x350 fp=0xc42015d1c0 sp=0xc42015d160
runtime.(*_type).typeOff(0xc4200ac700, 0xffffffed, 0x671d87)
	/usr/local/go/src/runtime/type.go:239 +0x33 fp=0xc42015d1e8 sp=0xc42015d1c0
runtime.additab(0x7f2f9e916440, 0x101)
	/usr/local/go/src/runtime/iface.go:112 +0x1e2 fp=0xc42015d2d0 sp=0xc42015d1e8
runtime.getitab(0x6b6840, 0xc4200ac700, 0x4a1701, 0xc4200ac700)
	/usr/local/go/src/runtime/iface.go:79 +0x184 fp=0xc42015d368 sp=0xc42015d2d0
runtime.assertE2I2(0x6b6840, 0xc4200ac700, 0xc42014d880, 0x0, 0x0, 0x0)
	/usr/local/go/src/runtime/iface.go:294 +0x43 fp=0xc42015d398 sp=0xc42015d368
fmt.(*pp).handleMethods(0xc4200b63c0, 0xc400000076, 0x100)
	/usr/local/go/src/fmt/print.go:560 +0x70 fp=0xc42015d428 sp=0xc42015d398
fmt.(*pp).printValue(0xc4200b63c0, 0xc4200ac700, 0xc42012b6e8, 0x199, 0xc400000076, 0x3)
	/usr/local/go/src/fmt/print.go:695 +0x2d6b fp=0xc42015d620 sp=0xc42015d428
fmt.(*pp).printValue(0xc4200b63c0, 0xc42012b7a0, 0xc42012b6e0, 0x199, 0xc400000076, 0x2)
	/usr/local/go/src/fmt/print.go:778 +0x21de fp=0xc42015d818 sp=0xc42015d620
fmt.(*pp).printValue(0xc4200b63c0, 0xc42012b800, 0xc42012b6e0, 0x199, 0xc400000076, 0x1)
	/usr/local/go/src/fmt/print.go:778 +0x21de fp=0xc42015da10 sp=0xc42015d818
fmt.(*pp).printValue(0xc4200b63c0, 0xc42014f5c0, 0xc42012b6e0, 0x16, 0x76, 0x0)
	/usr/local/go/src/fmt/print.go:848 +0x1dd1 fp=0xc42015dc08 sp=0xc42015da10
fmt.(*pp).printArg(0xc4200b63c0, 0xc42014f5c0, 0xc42012b6e0, 0x76)
	/usr/local/go/src/fmt/print.go:682 +0x217 fp=0xc42015dc90 sp=0xc42015dc08
fmt.(*pp).doPrintln(0xc4200b63c0, 0xc42015de68, 0x1, 0x1)
	/usr/local/go/src/fmt/print.go:1138 +0xa1 fp=0xc42015dd08 sp=0xc42015dc90
fmt.Fprintln(0x826fc0, 0xc42008e008, 0xc42015de68, 0x1, 0x1, 0xc42012b6e0, 0x82df60, 0xc42012b800)
	/usr/local/go/src/fmt/print.go:247 +0x5c fp=0xc42015dd70 sp=0xc42015dd08
fmt.Println(0xc42015de68, 0x1, 0x1, 0xc42014d720, 0xc42014f5c0, 0xc42012b6e0)
	/usr/local/go/src/fmt/print.go:257 +0x57 fp=0xc42015ddc0 sp=0xc42015dd70
main.main()
	/home/shatranj/GoLang/gorpc/src/app/testRetag.go:62 +0x723 fp=0xc42015df88 sp=0xc42015ddc0
runtime.main()
	/usr/local/go/src/runtime/proc.go:185 +0x20a fp=0xc42015dfe0 sp=0xc42015df88
runtime.goexit()
	/usr/local/go/src/runtime/asm_amd64.s:2197 +0x1 fp=0xc42015dfe8 sp=0xc42015dfe0

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
	/usr/local/go/src/runtime/asm_amd64.s:2197 +0x1
exit status 2

go version:

go version go1.8 linux/amd64

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.