How to Use
- clone this repository and cd ./mgen
go install
- run
mgen -c
- type information, following guide
- output is shown in stdout. if you specified
-c
option, output is copied to clipboard.
Options
% mgen -h
Usage of ifgen:
-c copy to clipboard
Output is like below
% mgen -c
struct name: User
Field(if nothing type ! and enter): Name
Type: string
Field(if nothing type ! and enter): Age
Type: int64
Field(if nothing type ! and enter): URL
Type: string
Field(if nothing type ! and enter): !
type User struct {
Name string
Age int64
URL string
}
func NewUser(
name string, age int64, url string,
) User {
return User{
Name: name,
Age: age,
URL: url,
}
}
func TestUser_NewUser(t *testing.T) {
t.Parallel()
type in struct {
name string
age int64
url string
}
tests := []struct {
name string
in in
out User
}{
{
name: "success",
in: in{
name: "name001", age: 15, url: "url001",
},
out: User{
Name: "name001", Age: 15, URL: "url001",
},
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
out := NewUser(
tt.in.name, tt.in.age, tt.in.url,
)
assert.Equal(t, tt.out, out)
})
}
}