fillstruct - fills a struct literal with default values
For example, given the following types,
type User struct {
ID int64
Name string
Addr *Address
}
type Address struct {
City string
ZIP int
LatLng [2]float64
}
the following struct literal
var frank = User{}
becomes:
var frank = User{
ID: 0,
Name: "",
Addr: &Address{
City: "",
ZIP: 0,
LatLng: [2]float64{
0.0,
0.0,
},
},
}
after applying fillstruct.
% go install github.com/CaiJinKen/[email protected]
% fillstruct -file=<filename> -line=<line number> -writeback=true
or
% fillstruct -file <filename> -line <line number> -writeback
Flags:
-file string
filename
-line int
line number of the struct literal
-only-changed
just print changed line, false will print all info
-std-out
print info into stdout (default true)
-version string
print fillstruct version
-writeback
writeback to the file
If -offset as well as -line are present, then the tool first uses the more specific offset information. If there was no struct literal found at the given offset, then the line information is used.
what types of assign statement supported? You can find use case in test.go for detail.
- global variable
- general local variable
- local variable in local function
- local variable in function of a return statement
sure! You can add vim-fillstruct plugin in vim/neovim