apiutil

package
v1.0.0-...-4f7f1ef Latest Latest
Warning

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

Go to latest
Published: May 31, 2016 License: LGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorAPIRegisted2 = errutil.NewFactory("API already registed for method=%q pattern=%1")
)

errors

View Source
var (
	ErrorRequestParamNotFound1 = errutil.NewFactory("param %q not found in request map")
)

errors

Functions

func AnalyzeStructParams

func AnalyzeStructParams(
	requestStruct interface{},
	funcArgs *RequestParams,
	params *RequestParams,
	extraStructs *ExtraStructs,
)

AnalyzeStructParams analyze requestStruct fields and fill funcArgs/params

func Any

func Any(pattern string, handlers ...martini.Handler)

func BindRouter

func BindRouter(router martini.Router)

BindRouter bind all registed apis to martini router

func Delete

func Delete(pattern string, handlers ...martini.Handler)

func Get

func Get(pattern string, handlers ...martini.Handler)

func GetAPINameByPattern

func GetAPINameByPattern(
	pattern string,
	repl func(string) string,
) string

GetAPINameByPattern return API name by analyze pattern

func GetFuncNameByPattern

func GetFuncNameByPattern(
	pattern string,
	repl func(string) string,
) string

GetFuncNameByPattern return API name by analyze pattern

func GetPathByPattern

func GetPathByPattern(
	pattern string,
	repl func(string) string,
) string

GetPathByPattern return api path by analyze pattern

func Head(pattern string, handlers ...martini.Handler)

func Options

func Options(pattern string, handlers ...martini.Handler)

func Patch

func Patch(pattern string, handlers ...martini.Handler)

func Post

func Post(pattern string, handlers ...martini.Handler)

func Put

func Put(pattern string, handlers ...martini.Handler)

func Regist

func Regist(method string, pattern string, handlers ...martini.Handler)

Regist API

func RegistedApiMap

func RegistedApiMap() map[string]apiConfig

RegistedApiMap return all registed API

func RegistedSortedApiMap

func RegistedSortedApiMap() []apiConfig

RegistedSortedApiMap return all registed API sorted

func ReplaceContinuousNewLine

func ReplaceContinuousNewLine(src string, repl string) string

ReplaceContinuousNewLine replace continuous newline

func Reset

func Reset()

Reset all registed API, used for testing

func TailComma

func TailComma(idx int, params RequestParams) string

TailComma return "," if idx is the last of params

func TrimReplaceStartSpace

func TrimReplaceStartSpace(src string, repl string) string

TrimReplaceStartSpace trim space and replace start space with repl per line

func TrimStartSpaceEmptyLine

func TrimStartSpaceEmptyLine(src string) (result string, err error)

TrimStartSpaceEmptyLine remove empty line with start space

func WithInfo

func WithInfo(info interface{}) *apiOrm

Types

type ExtraStruct

type ExtraStruct struct {
	FieldName string
	FieldType reflect.Type
	Params    RequestParams
}

ExtraStruct contain struct name, type info, and params info

type ExtraStructs

type ExtraStructs []*ExtraStruct

ExtraStructs is slice type of ExtraStruct

func (*ExtraStructs) Upsert

func (p *ExtraStructs) Upsert(param string, paramType reflect.Type) *ExtraStruct

Upsert append ExtraStruct to ExtraStructs if not exist

type RequestInfo

type RequestInfo struct {
	APIName      string
	FuncName     string // FuncName := APIName with version suffix
	FuncArgs     RequestParams
	Path         string
	Params       RequestParams
	ExtraStructs ExtraStructs
}

RequestInfo contains request function name, params

func AnalyzeRequestStruct

func AnalyzeRequestStruct(
	pattern string,
	requestStruct interface{},
	replFuncName func(param string) string,
	replPath func(param string) string,
) (reqinfo RequestInfo)

AnalyzeRequestStruct analyze request struct object, produce request struct map struct field with tag `apijs:"inherit"` will extend the field arguments repl used for custom function name generator

type RequestParam

type RequestParam struct {
	FieldName string
	FieldType reflect.StructField
}

RequestParam contain param name and type info

type RequestParams

type RequestParams []RequestParam

RequestParams is slice type of RequestParam

func (*RequestParams) Clone

func (p *RequestParams) Clone() RequestParams

Clone a new RequestParams

func (*RequestParams) Delete

func (p *RequestParams) Delete(params ...string) (err error)

Delete param in RequestParams

func (*RequestParams) FieldNames

func (p *RequestParams) FieldNames() (results []string)

FieldNames return field names in string slice type

func (*RequestParams) Upsert

func (p *RequestParams) Upsert(param string, paramType *reflect.StructField)

Upsert append RequestParam to RequestParams if not exist

Jump to

Keyboard shortcuts

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