common

package
v0.0.0-...-17fbf12 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2017 License: MIT Imports: 23 Imported by: 14

Documentation

Overview

Package common provides common operation helpers to the generators

Index

Constants

This section is empty.

Variables

View Source
var HandshakeConfig = plugin.HandshakeConfig{
	ProtocolVersion:  1,
	MagicCookieKey:   "GENE_PLUGIN",
	MagicCookieValue: "gene-cookie",
}

HandshakeConfig is the contract between rpc plugin clients and servers.

View Source
var TemplateFuncs = template.FuncMap{
	"Pointerize":              stringext.Pointerize,
	"ToLower":                 strings.ToLower,
	"ToUpper":                 strings.ToUpper,
	"Join":                    strings.Join,
	"ToLowerFirst":            stringext.ToLowerFirst,
	"ToUpperFirst":            stringext.ToUpperFirst,
	"AsComment":               stringext.AsComment,
	"DepunctWithInitialUpper": stringext.DepunctWithInitialUpper,
	"DepunctWithInitialLower": stringext.DepunctWithInitialLower,
	"Equal":                   stringext.Equal,
	"ToFieldName":             stringext.ToFieldName,
	"Argumentize":             schema.Argumentize,
	"SortedObjectSchemas":     SortedObjectSchemas,
	"SortedSchema":            schema.SortedSchema,
}

TemplateFuncs provides utility functions for template operations

Functions

func IsIn

func IsIn(s string, ts ...string) bool

IsIn checks if the first param is in the following ones

func Proces

func Proces(o *Op, req *Req, res *Res) error

Proces generates content for other plugins

func ProcesRoot

func ProcesRoot(o *Op, req *Req, res *Res) error

func ProcessSingle

func ProcessSingle(o *Op, def *schema.Schema, settings schema.Generator) ([]byte, error)

ProcessSingle generates output for only one level of a schema

func Read

func Read(path string) (*schema.Schema, error)

Read reads the given file and creates a new module out of it

func ReadJSON

func ReadJSON(path string) (string, error)

ReadJSON reads the given file and returns it as json string

func RunTest

func RunTest(t *testing.T, g Generator, testData string, expecteds []string)

RunTest provides a basic test runner for gene packages

func SortedObjectSchemas

func SortedObjectSchemas(m map[string]*schema.Schema) []*schema.Schema

SortedObjectSchemas filters object schemas and sorts them

func TestEquals

func TestEquals(tb testing.TB, exp, act interface{})

TestEquals checks if the exp and act is deeply equal

func WriteOutput

func WriteOutput(output []Output) error

WriteOutput writes output slice

Types

type Context

type Context struct {
	Config *config.Config
}

Context holds contextual information for ongoing operations.

func NewContext

func NewContext() *Context

NewContext creates a new context with sane defaults.

type Generator

type Generator interface {
	Generate(*Req, *Res) error
}

Generator is the basic interface for plugin operations.

type GeneratorPlugin

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

GeneratorPlugin provides basic plugin system

func NewGeneratorPlugin

func NewGeneratorPlugin(g Generator) *GeneratorPlugin

NewGeneratorPlugin creates a new plugin out of given Generator

func (*GeneratorPlugin) Client

func (g *GeneratorPlugin) Client(b *plugin.MuxBroker, c *rpc.Client) (interface{}, error)

Client provides client functionality for plugins

func (*GeneratorPlugin) Server

func (g *GeneratorPlugin) Server(*plugin.MuxBroker) (interface{}, error)

Server provides server functionality for plugins

type GeneratorRPCClient

type GeneratorRPCClient struct{ Client *rpc.Client }

GeneratorRPCClient provides rpc client functionality.

func (*GeneratorRPCClient) Generate

func (g *GeneratorRPCClient) Generate(req *Req, res *Res) error

Generate implements generator interface.

type GeneratorRPCServer

type GeneratorRPCServer struct{ Impl Generator }

GeneratorRPCServer provides rpc server functionality.

func (*GeneratorRPCServer) Generate

func (g *GeneratorRPCServer) Generate(req *Req, res *Res) error

Generate implements generator interface.

type Op

type Op struct {
	Name           string
	Template       string
	PathFunc       func(data *TemplateData) string
	Clear          bool
	DoNotFormat    bool
	FormatSource   bool
	RemoveNewLines bool
	PostProcessors []PostProcessor
	// contains filtered or unexported fields
}

Op holds the operation information for processing.

type Output

type Output struct {
	Content       []byte
	Path          string
	DoNotFormat   bool
	DoNotOverride bool
}

Output holds response data for a plugin request.

type PluginStore

type PluginStore struct {
	Plugins map[string]string
	Clients map[string]*plugin.Client
}

PluginStore holds plugin names and their clients

func Discover

func Discover(prefix string) (*PluginStore, error)

Discover searches for plugins located nearby with this binary and in PATH, matching given prefix name

func (*PluginStore) Shutdown

func (g *PluginStore) Shutdown() error

type PostProcessor

type PostProcessor func([]byte) []byte

PostProcessor holds to be applied operations after generation is done.

type Req

type Req struct {
	Schema    *schema.Schema
	SchemaStr string
	Context   *Context
}

Req holds request data for rpc calls

type Res

type Res struct {
	Output []Output
}

Res holds response for rpc calls

type TemplateData

type TemplateData struct {
	ModuleName  string
	Schema      *schema.Schema
	Definitions []*schema.Schema
	Settings    *schema.Generator
}

TemplateData holds template related data for processing

Jump to

Keyboard shortcuts

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