dranikpg / dto-mapper Goto Github PK
View Code? Open in Web Editor NEWgo library for complex struct mapping
License: MIT License
go library for complex struct mapping
License: MIT License
What are any solutions to improve performance when using DTO pattern automation? It's looking good to me but I still considering performance ^^
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!
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.