swipe

package module
v2.0.0-alpha.11 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2020 License: MIT Imports: 0 Imported by: 0

README

Swipe

Build Status GitHub license

Swipe is a code generation tool that automates the creation of repetitively used code. Configuration parameters are presented in Swipe as parameters of the Golang function, using explicit initialization instead of global variables or reflections.

Installation

To install Swipe, follow these steps:

go get github.com/swipe-io/swipe/cmd/swipe

check that "$GOPATH/bin "is added to your "$PATH".

Documentation

User guide

Documentation

Overview

Package swipe is a code generation tool that automates the creation of repetitively used code. Configuration parameters are presented in Swipe as parameters of the Golang function, using explicit initialization instead of global variables or reflections.

Swipe generates code using an option: a function that calls functions that define the generation parameters. Using Swipe, you describe the generation parameters in the option, and then Swipe generates the code.

1. The "function as an option" approach is used to configure generation.

2. All code that is not associated with the generation parameters will not be copied to the generated file.

3. Function with a `swipe.Build` option inserted in the body. `swipe.Build` will not be transferred to the generated code.

If you want the generate code, you can run:

swipe ./pkg/...

Full example:

 // +build swipe

 package jsonrpc

 import (
	  "github.com/swipe-io/swipe/v2/fixtures/service"

	  . "github.com/swipe-io/swipe/v2/pkg/swipe"
 )

 func Swipe() {
	Build(
		Service(
			(*service.Interface)(nil),
			Transport("http",
				ClientEnable(),
				Openapi(
					OpenapiOutput("/../../docs"),
					OpenapiVersion("1.0.0"),
				),
			),
			Logging(),
			Instrumenting(),
		),
	  )
 }

Index

Constants

View Source
const Version = "v2.0.0-alpha.11"

Variables

This section is empty.

Functions

func Build

func Build(Option)

Build the basic option for defining the generation.

Types

type ConfigEnvOption

type ConfigEnvOption string

A ConfigEnvOption is an option env config.

type GatewayOption

type GatewayOption string

func GatewayService

func GatewayService(iface interface{}, opts ...GatewayServiceOption) GatewayOption

type GatewayServiceMethodOption

type GatewayServiceMethodOption string

type GatewayServiceOption

type GatewayServiceOption string

func GatewayServiceMethod

func GatewayServiceMethod(signature interface{}, opts ...GatewayServiceMethodOption) GatewayServiceOption

type InterfaceOption

type InterfaceOption string

type MethodOption

type MethodOption string

A MethodOption is an option method.

func ClientDecodeResponseFunc

func ClientDecodeResponseFunc(interface{}) MethodOption

ClientDecodeResponseFunc sets a function to extract the user's domain response object from the response object.

func ClientEncodeRequestFunc

func ClientEncodeRequestFunc(interface{}) MethodOption

ClientEncodeRequestFunc sets the function to encode the passed request object into an object.

func Instrumenting

func Instrumenting(enable bool) MethodOption

InstrumentingEnable a option enabled/disable instrumenting (collect metrics) middleware.

func InstrumentingDisable

func InstrumentingDisable() MethodOption

InstrumentingDisable a option disable instrumenting (collect metrics) middleware.

func Logging

func Logging(enable bool) MethodOption

Logging a option enabled/disable logging middleware.

func LoggingParams

func LoggingParams(includes []string, excludes []string) MethodOption

func RESTHeaderVars

func RESTHeaderVars([]string) MethodOption

HeaderVars sets the key/value array to get method values from headers, where the key is the name of the method parameter, and the value is the name of the header.

func RESTMethod

func RESTMethod(string) MethodOption

RESTMethod sets http method, default is GET.

func RESTPath

func RESTPath(string) MethodOption

Path sets http path, default is lowecase method name with the prefix "/", for example: the Get method will look like " /get".

func RESTQueryVars

func RESTQueryVars([]string) MethodOption

QueryVars sets the key/value array to get method values from query args, where the key is the name of the method parameter, and the value is the name of the query args.

func RESTWrapResponse

func RESTWrapResponse(string) MethodOption

WrapResponse wrap the response from the server to an object, for example if you want to return as:

{data: { you response data }}

need to add option:

...code here...
WrapResponse("data")
... code here ...

func ServerDecodeRequestFunc

func ServerDecodeRequestFunc(interface{}) MethodOption

ServerDecodeRequestFunc sets a function to extract the user's domain request object from the request object.

func ServerEncodeResponseFunc

func ServerEncodeResponseFunc(interface{}) MethodOption

ServerEncodeResponseFunc sets the encoding function of the passed response object to the response writer.

type OpenapiServerOption

type OpenapiServerOption string

A OpenapiServerOption is an openapi concrete server option.

type OpenapiServersOption

type OpenapiServersOption string

A OpenapiServersOption is an openapi servers option.

type Option

type Option string

A Option is an option for a Swipe.

func ConfigEnv

func ConfigEnv(optionsStruct interface{}) Option

ConfigEnv option for config generation.

To generate a configuration loader, you can use the swipe.ConfigEnv option. The optionsStruct parameter is a pointer to the configuration structure.

The option can work with all primitives, including datetime, and an array of primitives.

The option supports nested structures.

To use the default value, just specify it as a value in the structure.

Default func name is `LoadConfig`.

You can use structure tags to control generation:

env  - name of environment var, options: `required`.

flag - name of flag, enable as the console flag.

desc - description for String function.

func ConfigEnvDocEnable

func ConfigEnvDocEnable() Option

ConfigEnvDocEnable enable markdown doc generate.

func ConfigEnvDocOutput

func ConfigEnvDocOutput(output string) Option

ConfigEnvDocOutput output path markdown doc generate.

func ConfigEnvFuncName

func ConfigEnvFuncName(name string) Option

func Gateway

func Gateway(services ...GatewayOption) Option

func Service

func Service(opts ...ServiceOption) Option

Service a option that defines the generation of transport, metrics, tracing, and logging for gokit. Given iface is nil pointer interface, for example:

(*pkg.Iface)(nil)

type ReadmeOption

type ReadmeOption string

type ServiceOption

type ServiceOption string

A ServiceOption is an option service.

func ClientsEnable

func ClientsEnable(langs []string) ServiceOption

ClientsEnable enable generate Golang, JavaScript client.

func HTTPFast

func HTTPFast() ServiceOption

HTTPFast enable generate fast http server.

func HTTPServer

func HTTPServer() ServiceOption

ServerDisabled enable generate http server.

func Interface

func Interface(iface interface{}, name string) ServiceOption

func JSONRPCDocEnable

func JSONRPCDocEnable() ServiceOption

JSONRPCDocEnable enable for generate markdown JSON RPC doc.

func JSONRPCDocOutput

func JSONRPCDocOutput(output string) ServiceOption

JSONRPCDocOutput change output dir for generate markdown JSON RPC doc.

func JSONRPCEnable

func JSONRPCEnable() ServiceOption

JSONRPCEnable enabled use JSON RPC instead of REST.

func JSONRPCPath

func JSONRPCPath(string) ServiceOption

JSONRPCPath sets the end point for transport.

func MethodDefaultOptions

func MethodDefaultOptions(...MethodOption) ServiceOption

MethodDefaultOptions option for defining for all methods default settings.

func MethodOptions

func MethodOptions(signature interface{}, opts ...MethodOption) ServiceOption

MethodOptions option for defining method settings. Given signature is interface method, for example:

pkg.Iface.Create

func OpenapiContact

func OpenapiContact(name, email, url string) ServiceOption

OpenapiContact sets openapi contact.

func OpenapiEnable

func OpenapiEnable() ServiceOption

OpenapiEnable enabled generate openapi documentation.

func OpenapiInfo

func OpenapiInfo(title, description, version string) ServiceOption

OpenapiInfo sets info.

func OpenapiLicence

func OpenapiLicence(name, url string) ServiceOption

OpenapiLicence sets openapi licence.

func OpenapiOutput

func OpenapiOutput(string) ServiceOption

OpenapiOutput sets output directory, path relative to the file, default is "./".

func OpenapiServer

func OpenapiServer(description, url string) ServiceOption

OpenapiServer sets openapi server.

func OpenapiTags

func OpenapiTags(methods []interface{}, tags []string) ServiceOption

OpenapiTags sets docs tags for method.

func ReadmeEnable

func ReadmeEnable() ServiceOption

ReadmeEnable enable for generate readme markdown for service.

func ReadmeOutput

func ReadmeOutput(string) ServiceOption

func ReadmeTemplatePath

func ReadmeTemplatePath(string) ServiceOption

func ServiceNamePrefix

func ServiceNamePrefix(string) ServiceOption

Name override service name prefix.

Jump to

Keyboard shortcuts

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