ifacecodegen

package module
v0.0.0-...-889be8f Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2017 License: MIT Imports: 14 Imported by: 0

README

ifacecodegen

Build Status GoDoc

Go tool and library for generating code from the template using interface definition.

Installation

go get -u github.com/fredipevcin/ifacecodegen/cmd/ifacecodegen

Running ifacecodegen

ifacecodegen -source examples/interface.go -destination -

or

cat examples/interface.go | ifacecodegen

Other options

ifacecodegen -h

Examples

Example templates and interface are located in examples folder.

# example 1
ifacecodegen \
	-source examples/interface.go \
	-template examples/example1.tmpl \
	-destination - \
	-meta service=account \
	-imports "opentracing=github.com/opentracing/opentracing-go,tracinglog=github.com/opentracing/opentracing-go/log"

# example 2
ifacecodegen \
	-source examples/interface.go \
	-template examples/example2.tmpl \
	-destination -

Notes

Inspired by:

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(opts GenerateOptions) ([]byte, error)

Generate generates code

Types

type GenerateOptions

type GenerateOptions struct {
	Source          string
	Package         *Package
	Interfaces      []string
	Template        io.Reader
	OverridePackage string
	Imports         []*Import
	Meta            map[string]string
	Functions       template.FuncMap
}

GenerateOptions are options used to generate code

type Import

type Import struct {
	Package string
	Path    string
}

Import is a package name and path that is imported by another package.

type Interface

type Interface struct {
	Name    string
	Methods []*Method
}

Interface is an exported interface defined in a package.

type Method

type Method struct {
	Name string
	In   []*Parameter
	Out  []*Parameter
}

Method is a named function attached to an interface.

type Package

type Package struct {
	Name       string
	Interfaces []*Interface
}

Package is a container for all exported interfaces of a Google-golang package.

func Parse

func Parse(opts ParseOptions) (*Package, error)

Parse returns parsed package

type Parameter

type Parameter struct {
	Name string
	Type Type
}

Parameter is a named parameter used by a Method.

type ParseOptions

type ParseOptions struct {
	Source io.Reader
}

ParseOptions are options used to parse

type Type

type Type interface {
	String() string
}

Type is a Google-golang type definition that can be rendered into a valid Google-golang code snippet.

type TypeArray

type TypeArray struct {
	Len  int
	Type Type
}

TypeArray is a slice or array type.

func (*TypeArray) String

func (t *TypeArray) String() string

type TypeBuiltin

type TypeBuiltin string

TypeBuiltin is a built in Google-golang type such as "string" or "bool".

func (TypeBuiltin) String

func (t TypeBuiltin) String() string

type TypeChan

type TypeChan struct {
	ReadOnly  bool
	WriteOnly bool
	Type      Type
}

TypeChan is a channel type.

func (*TypeChan) String

func (t *TypeChan) String() string

type TypeExported

type TypeExported struct {
	Package string
	Type    Type
}

TypeExported is a user defined type that is exported from a package.

func (*TypeExported) String

func (t *TypeExported) String() string

type TypeFunc

type TypeFunc struct {
	In  []Type
	Out []Type
}

TypeFunc is an input type of a function.

func (*TypeFunc) String

func (t *TypeFunc) String() string

type TypeMap

type TypeMap struct {
	Key   Type
	Value Type
}

TypeMap is a user defined map type.

func (*TypeMap) String

func (t *TypeMap) String() string

type TypePointer

type TypePointer struct {
	Type Type
}

TypePointer is a pointer to another type.

func (*TypePointer) String

func (t *TypePointer) String() string

type TypeVariadic

type TypeVariadic struct {
	Type Type
}

TypeVariadic is any type that is prefixed by Ellipsis.

func (*TypeVariadic) String

func (t *TypeVariadic) String() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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