mgen

command
v0.0.0-...-c34ab15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 25, 2021 License: MIT Imports: 10 Imported by: 0

README

Tool to generate interface, struct, constructor, function at once

How to Use

  1. clone this repository and cd ./mgen
  2. go install
  3. run mgen -c
  4. type information, following guide
  5. 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)
		})
	}
}

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL