Coder Social home page Coder Social logo

petersunbag / coven Goto Github PK

View Code? Open in Web Editor NEW
27.0 27.0 9.0 60 KB

a fast converter for Go, support struct-to-struct, slice-to-slice and map-to-map non-reflection converting, type with nested pointers is supported.

License: MIT License

Go 94.72% Python 5.28%

coven's People

Contributors

petersunbag 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

Watchers

 avatar  avatar

coven's Issues

Error

type foobar struct {
    D int
}
type Foo struct {
    A []int
    B map[int64][]byte
    C byte
    foobar
}

type Bar struct {
    A []int
    B map[string]*string
    C *byte
    D int64
}

var c = NewConverter(Bar{}, Foo{})

func demo(){
    foo := Foo{[]int{}, map[int64][]byte{1: []byte{'a', 'b'}, 2: []byte{'b', 'a'}, 3: []byte{'c', 'd'}}, 6, foobar{11}}
    bar := Bar{}
    c.Convert(&bar, &foo)
    bytes, _ := json.Marshal(bar)
    fmt.Println(string(bytes))
}

image

Can you help me add a feature?

Add default tag and from tag.

type Bar struct {
    A []*int
    B map[string]*string
    C *byte
    D int64 `default:"1" from:"D1"`
}

Like this.
Or just implement default tag.

And use go mod, add a release.
Thank you!

Negligible:
If I implement map to struct, I can not apply this github.com/mitchellh/mapstructure

struct 中的 time.time 没转换成功

  • 测试代码如下
package main

import (
	"fmt"
	"github.com/petersunbag/coven"
	"time"
)

type A struct {
	Time time.Time
}

type B struct {
	Time time.Time
}

func main() {
	c, _ := coven.NewConverter(A{}, B{})
	tmp := time.Now()
	a := A{Time: tmp}
	b := B{}

	c.Convert(&a, &b)
	fmt.Println(b)
}

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.