Is there a library similar to DTO (data transfer object) in go language?

when using go for web development, orm can establish mappings between business objects and databases, but there is no library similar to dto in java, which can make a layer of isolation between the presentation layer and business objects.

for example, if I want to query all candidate and return it to the front end as json, then I must do this:

type Candidate struct {
    Address     string      `bson:"address" json:"address"` // owner
    PubKey      string      `bson:"pub_key" json:"pub_key"`
    Shares      int64       `bson:"shares" json:"shares"`
    VotingPower uint64      `bson:"voting_power" json:"voting_power"` // Voting power if pubKey is a considered a validator
    Description Description `bson:"description" json:"description"`  // Description terms for the candidate
}

however, this is coupling the UI object with the business object, which is somewhat unreasonable in terms of design and development. So, I would like to ask if there is a library similar to dto in the go language to do a layer of separation?

Mar.09,2021

this isolation, can't you just add a transformation to the business layer? It's not complicated


https://github.com/devfeel/mapper

Menu