Skip to content

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

Notifications You must be signed in to change notification settings

alekseikovrigin/structocaster

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

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

Watchers

Forks

Packages

 
 
 

Languages