apigen

command module
v0.0.0-...-19249b1 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2016 License: MIT Imports: 3 Imported by: 0

README

apigen

GoDoc

Code Generator in Go

Package uses the ast standard library to generate Go code from templates. The package API may change.

The package can do the following things:

  • Load a file
  • Create a new file
  • Copy a struct (with field comments and tags) to another package
  • Change the package name
  • Add imports
  • Create a new imports section
  • Print all comments in a package

Below is sample code to generate the code for a hello world application.

var err error
var arrImports []string

arrImports = append(arrImports, "fmt")

// Create the package
gt := tree.New("main")
gt.AddImportSection(arrImports)
gt.AddHelloMainFunc()

// Write to a file
err = gt.WriteFile("output/hello/hello.go", true, 0644, 0644)
if err != nil {
	log.Println(err)
	return
}

Here is the output:

package main

import (
	"fmt"
)

func main() {
	fmt.Println("hello world")
}

Issues

When copying structs, the comments above structs do not copy. I believe this is related to the way ast was first written because it was a very early package. Links to the comment issues: 11880 and 14629

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
cmd
spec

Jump to

Keyboard shortcuts

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