impl

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2018 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// <Annotation Val> first annotations. etc. @Get /item/{id} | @Get
	GetAnn        = "@Get" // path
	HeadAnn       = "@Head"
	PostAnn       = "@Post"
	PutAnn        = "@Put"
	PatchAnn      = "@Patch"
	DeleteAnn     = "@Delete"
	ConnectAnn    = "@Connect"
	OptionsAnn    = "@Options"
	TraceAnn      = "@Trace"
	BodyAnn       = "@Body"       // json | xml | form | multipart; default json
	SingleBodyAnn = "@SingleBody" // json | xml | form | multipart; default json; if singleBody, the type of single body var must be IOReader or Other
	ResultAnn     = "@Result"     // json | xml ; default json
	BaseAnn       = "@Base"
)
View Source
const (
	// <Annotation(Key) Val> second annotations. etc. @Header(Content-Type) multipart/form | @Header(Content-Type)
	ParamAnn  = "@Param"
	HeaderAnn = "@Header" // param type: string
	CookieAnn = "@Cookie" // param type: string
	FileAnn   = "@File"   // param type: string
)
View Source
const (

	// resp, error
	HttpResponse = "http_response"

	// req, error
	HttpRequest = "http_request"

	// resp, statusCode, error
	HTML = "html"
)
View Source
const (

	// resp, statusCode, error
	JSON = "json"

	// resp, statusCode, error
	XML = "xml"
)
View Source
const (

	// resp, statusCode, error
	Form = "form"

	// resp, statusCode, error
	Multipart = "multipart"
)
View Source
const (
	DuplicatedAnnotation           = "duplicated annotation"
	DuplicatedHttpMethod           = "duplicated http method"
	IdNotExist                     = "id does not exist"
	PatternIdTypeMustBeIntOrString = "id in pattern must be int or string"
	PatternKeyMustNotBeEmpty       = "key of pattern must not be empty"
	SingleBodyWithMultiBodyVars    = "singleBody with multi body vars"
	ConflictAnnotation             = "annotation conflict"
	UnsupportedAnnotationValue     = "annotation value is unsupported"
)
View Source
const (
	FieldBaseUrl = "baseUrl"
	FieldHeader  = "header"
	FieldCookies = "cookies"
)
View Source
const (
	// packages
	HttpPkg      = "net/http"
	EncodingJSON = "encoding/json"
	EncodingXML  = "encoding/xml"
	Bytes        = "bytes"
	Ioutil       = "io/ioutil"
	NetURL       = "net/url"
	IO           = "io"
	MultipartPkg = "mime/multipart"
	Textproto    = "net/textproto"
	OS           = "os"
	StringsPkg   = "strings"
	FormatPkg    = "fmt"
	UnHTMLPkg    = "github.com/Hexilee/unhtml"
)
View Source
const (
	// types
	IntToken    = "int"
	StringToken = "string"
	ErrorToken  = "error"
)
View Source
const (
	IdRegexp          = `\{[a-zA-Z_][0-9a-zA-Z_]*\}`
	StringPlaceholder = "%s"
	IntPlaceholder    = "%d"
)
View Source
const (
	// ids
	IdResult      = "genResult"
	IdRequest     = "genRequest"
	IdResponse    = "genResponse"
	IdClient      = "genClient"
	IdStatusCode  = "genStatusCode"
	IdError       = "genErr"
	IdUri         = "genUri"
	IdUrl         = "genFinalUrl"
	IdData        = "genData"
	IdResultData  = "genResultData"
	IdBody        = "genBody"
	IdDataMap     = "genDataMap"
	IdPartWriter  = "genPartWriter"
	IdBodyWriter  = "genBodyWriter"
	IdFile        = "genFile"
	IdFilePath    = "genFilePath"
	IdCookie      = "genCookie"
	IdHeaderKey   = "genHeaderKey"
	IdHeaderSlice = "genHeaderSlice"
	IdHeaderValue = "genHeaderValue"
	IdHeader      = "genHeader"
)
View Source
const (
	TypeInt = iota
	TypeString
	IOReader
	TypeFile
	Other
)
View Source
const (
	TokenType = "type"
	ZeroStr   = ""
	LF        = "\n"
)
View Source
const (
	TypeIOReader   = "IOReader"
	TypeErr        = "Err"
	TypeStatusCode = "StatusCode"
	TypeRequest    = "Request"
	TypeResponse   = "Response"
)
View Source
const (
	Src = `` /* 157-byte string literal not displayed */

)

Variables

Functions

func ConflictAnnotationError

func ConflictAnnotationError(ann string, value fmt.Stringer) error

func DuplicatedAnnotationError

func DuplicatedAnnotationError(ann string) error

func DuplicatedHttpMethodError

func DuplicatedHttpMethodError(method string) error

func GetType

func GetType(name string) types.Type

func IdNotExistError

func IdNotExistError(id string) error

func Impl

func Impl(service *Service, pkg string) (code string, err error)

func PatternIdTypeMustBeIntOrStringError

func PatternIdTypeMustBeIntOrStringError(id string) error

func UnsupportedAnnotationValueError

func UnsupportedAnnotationValueError(ann, value string) error

Types

type BodyMeta

type BodyMeta struct {
	*PatternMeta
	// contains filtered or unexported fields
}

type BodyType

type BodyType string

type IdList

type IdList map[string]bool

type Method

type Method struct {
	*types.Func

	*MethodMeta
	// contains filtered or unexported fields
}

func NewMethod

func NewMethod(srv *Service, rawMethod *types.Func) *Method

type MethodMeta

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

func (*MethodMeta) TryAddCookie

func (meta *MethodMeta) TryAddCookie(key, value string) (err error)

func (*MethodMeta) TryAddHeader

func (meta *MethodMeta) TryAddHeader(key, value string) (err error)

func (*MethodMeta) TryAddParam

func (meta *MethodMeta) TryAddParam(key, pattern string, typ ParamType) (err error)

func (*MethodMeta) TrySetBodyType

func (meta *MethodMeta) TrySetBodyType(value string) (err error)

func (*MethodMeta) TrySetMethod

func (meta *MethodMeta) TrySetMethod(httpMethod, uriPattern string) (err error)

func (*MethodMeta) TrySetResultType

func (meta *MethodMeta) TrySetResultType(value string) (err error)

func (*MethodMeta) TrySetSingleBodyType

func (meta *MethodMeta) TrySetSingleBodyType(value string) (err error)

type ParamMeta

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

func NewParamMeta

func NewParamMeta(param *types.Var) (meta *ParamMeta)

type ParamType

type ParamType int

type PatternMeta

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

type Service

type Service struct {
	*ServiceMeta
	// contains filtered or unexported fields
}

func NewService

func NewService(name string, info *types.Info) *Service

func (*Service) Complete

func (srv *Service) Complete() bool

func (*Service) InitComments

func (srv *Service) InitComments(cmap ast.CommentMap) *Service

func (*Service) SetMethod

func (srv *Service) SetMethod(rawMethod *types.Func)

func (Service) String

func (srv Service) String() string

func (*Service) TryAddField

func (srv *Service) TryAddField(node *ast.Field)

func (*Service) TrySetNode

func (srv *Service) TrySetNode(node *ast.GenDecl)

type ServiceMeta

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

Jump to

Keyboard shortcuts

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