Giter VIP home page Giter VIP logo

dto-mapper's People

Contributors

dranikpg avatar osendo 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

dto-mapper's Issues

reflect.Value.Set using value obtained using unexported field

Hey! I'm trying to convert uuid.UUID to string, but getting error:
reflect.Value.Set using value obtained using unexported field

My conv func looks like this:

m := dto.Mapper{}
m.AddConvFunc(func(id uuid.UUID, m *dto.Mapper) (string, error) {
    return id.String(), nil
})

I try to map next struct:

// User is the model entity for the User schema.
type User struct {
	config `json:"-"`
	// ID of the ent.
	ID uuid.UUID `json:"id,omitempty"`
	// CreatedAt holds the value of the "created_at" field.
	CreatedAt time.Time `json:"created_at,omitempty"`
	// UpdatedAt holds the value of the "updated_at" field.
	UpdatedAt time.Time `json:"updated_at,omitempty"`
	// DeletedAt holds the value of the "deleted_at" field.
	DeletedAt *time.Time `json:"deleted_at,omitempty"`
	// AuthID holds the value of the "auth_id" field.
	AuthID uuid.UUID `json:"auth_id,omitempty"`
	// Email holds the value of the "email" field.
	Email string `json:"email,omitempty"`
	// Username holds the value of the "username" field.
	Username string `json:"username,omitempty"`
	// Password holds the value of the "password" field.
	Password string `json:"-"`
	// FirstName holds the value of the "first_name" field.
	FirstName string `json:"first_name,omitempty"`
	// LastName holds the value of the "last_name" field.
	LastName string `json:"last_name,omitempty"`
	// Bio holds the value of the "bio" field.
	Bio string `json:"bio,omitempty"`
	// Location holds the value of the "location" field.
	Location string `json:"location,omitempty"`
	// Github holds the value of the "github" field.
	Github string `json:"github,omitempty"`
	// Gitlab holds the value of the "gitlab" field.
	Gitlab string `json:"gitlab,omitempty"`
	// Microsoft holds the value of the "microsoft" field.
	Microsoft string `json:"microsoft,omitempty"`
	// Linkedin holds the value of the "linkedin" field.
	Linkedin string `json:"linkedin,omitempty"`
	// Google holds the value of the "google" field.
	Google string `json:"google,omitempty"`
	// DefOrgID holds the value of the "def_org_id" field.
	DefOrgID *uuid.UUID `json:"def_org_id,omitempty"`
	// Timezone holds the value of the "timezone" field.
	Timezone string `json:"timezone,omitempty"`
	// Flags holds the value of the "flags" field.
	Flags int `json:"flags,omitempty"`
	// Prefs holds the value of the "prefs" field.
	Prefs map[string]interface{} `json:"prefs,omitempty"`
	// LoginAt holds the value of the "login_at" field.
	LoginAt *time.Time `json:"login_at,omitempty"`
	// Edges holds the relations/edges for other nodes in the graph.
	// The values are being populated by the UserQuery when eager-loading is set.
	Edges        UserEdges `json:"edges"`
	selectValues sql.SelectValues
}

That is ent model and it is autogenerated, so I can't to edit it (I can, but after regenerate all updates will be lost).

Help pls!

Performance

What are any solutions to improve performance when using DTO pattern automation? It's looking good to me but I still considering performance ^^

Panic on nil pointers in structs

Hi,

When mapping from a struct, to a struct, either of which contain nil pointers, the mapValue function will panic on the following line:

tk, fk := toRv.Type().Kind(), fromRv.Type().Kind()

This is due to a nil pointer dereference

The following code snippet skips mapValues if either side is nil:

func (m *Mapper) mapValue(toRv, fromRv reflect.Value) (returnError error) { if !toRv.IsValid() || !fromRv.IsValid() { return }

That works for me but unsure of any unintended consequences.

Thanks,

Tom

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.