Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Gen-struct-fields is a tool to generate the names of the structure fields in various formats.

License

NotificationsYou must be signed in to change notification settings

abramlab/gen-struct-fields

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gen-struct-fields is a tool to generate the names of the structure fields in various formats in Go code.

The generated code can be used, for example, to simplify work with the database and etc.

Install

Gen-struct-fields can be installed as any other go command:

go get github.com/abramlab/gen-struct-fields@v0.1.2

After that, thegen-struct-fields executable will be in "$GOPATH/bin" folder, and you can use it withgo generate

How to use

gen-struct-fields -struct=User -custom_name=user

or with go generate:

//go:generate gen-struct-fields -struct=User -custom_name=user

By default, for each structure will be generated a separate file, with name: <struct_name>_fields.go.

You can useoutput tag to specified custom output file name, then all data will be generated in it.

gen-struct-fields -struct=User -output=custom_generated_file.go

For multiple generation, separate tag struct value with coma, for example:

gen-struct-fields -struct=User,Car,Plane -tag=custom_tag -custom_name=user,,plane

will generate fields forUser,Car,Plane structs with custom names forUser andPlane.

If you want to specify custom tag name(by default it isfield), use "-tag":

gen-struct-fields -struct=User -custom_name=user -tag=custom_tag

Simple example

Initial data:

//go:generate gen-struct-fields -struct=User -tag=custom_tag -custom_name=usertype User struct {Name     string `custom_tag:"name"`Login    string `custom_tag:"username"`Password string `custom_tag:"-"`AuthType int    `custom_tag:"auth_type"`}

Output(generated) data:

const UserName = "user"var UserFields = struct {Name     stringLogin    stringAuthType string}{Name:     "name",Login:    "username",AuthType: "auth_type",}var UserFieldsArray = []string{UserFields.Name,UserFields.Login,UserFields.AuthType,}

About

Gen-struct-fields is a tool to generate the names of the structure fields in various formats.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2026 Movatter.jp