gogen

package module
v0.0.0-...-9082933 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2015 License: MIT Imports: 12 Imported by: 0

README

gogen

gogen is a struct base go generate library.

Usage

$ go get github.com/kyokomi/gogen

Example

main.go

main.go

package main

//go:generate genexample
type Hoge struct {
	Name    string
	Num     int
	Message string
}

func main() {

	h := Hoge{
		Name: "hoge",
		Num: 1,
		Message: "test",
	}
	h.Sample()
}
generator install
$ go install github.com/kyokomi/gogen/example/genexample

genexample source

generate
$ cd ./example
$ go generate
output

main_gen.go

package main

import (
	"fmt"
)


// Sample sample code
func (z *Hoge) Sample() {

	fmt.Println(z.Name)

	fmt.Println(z.Num)

	fmt.Println(z.Message)

}
Run Sample
$ go run main.go main_gen.go
hoge
1
test

TODO

  • paser部分でmsgp/parseを使うのをやめる
  • gen構造体でmsgp/genを使うのをやめる
  • go generate --debugでログがでるようにする(今は全部でてる)
  • testコードを書く
  • documentを書く

LICENSE

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GenerateFunc

type GenerateFunc func(w io.Writer, p *gen.Ptr) error

GenerateFunc generateするロジック

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator go generateの中核

func NewGenerator

func NewGenerator(inFile, outFile, pkgName string, imports ...string) *Generator

NewGenerator Generatorを生成する

func (Generator) DoAll

func (g Generator) DoAll(executeFunc GenerateFunc) error

DoAll GenerateFuncを元にgenerateする

func (Generator) DoAllTemplate

func (g Generator) DoAllTemplate(t *template.Template) error

DoAllTemplate templateを元にgenerateする

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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