Skip to content

Latest commit

 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Structocaster

Allows you to extract only the required fields from the structures and present them in the required format

type User struct {
	ID          int
	Name        string
	Surname     string
	Certificate Passport
}
type Passport struct {
	Serial      string
	CityOfBirth CityOfBirth
}
type CityOfBirth struct {
	Name string
}

type UserToReport struct {
	UID  int
	Name string
	G    string
	From City
}

type City struct {
	Title string `out:"Certificate.CityOfBirth.Name"`
}

Required fields are specified using tags or taken with a matching name from the same nesting level

UserFromDB := User{
	ID:      12,
	Name:    "Aleksei",
	Surname: "Kovrigin",
	Certificate: Passport{
		Serial: "DF374-23479",
		CityOfBirth: CityOfBirth{
			Name: "Kirov",
		},
	},
}

As := City{Title: ""}
UserToReport := UserToReport{
	UID:  13,
	Name: "",
	From: As,
}

structocaster.Cast(&UserFromDB, &UserToReport)

In the issue:

{
        "UID": 13,
        "Name": "Aleksei",
        "G": "",
        "From": {
                "Title": "Kirov"
        }
}

About

Allows you to extract only the required fields from the structures and present them in the required format

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages