spec

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Annotation

type Annotation struct {
	Properties map[string]string
}

Annotation defines key-value

type ApiSpec

type ApiSpec struct {
	Info    Info
	Syntax  ApiSyntax
	Imports []Import
	Types   []Type
	Service Service
}

ApiSpec describes a api file

type ApiSyntax

type ApiSyntax struct {
	Version string
}

ApiSyntax describes the syntax grammar

type ArrayType

type ArrayType struct {
	RawName string
	Value   Type
}

ArrayType describes a slice for api

func (ArrayType) Name

func (t ArrayType) Name() string

Name returns a slice string, such as []int

type AtDoc

type AtDoc struct {
	Properties map[string]string
	Text       string
}

AtDoc describes a metadata for api grammar: @doc(...)

type DefineStruct

type DefineStruct struct {
	RawName string
	Members []Member
	Docs    Doc
}

DefineStruct describes api structure

func (DefineStruct) GetBodyMembers

func (t DefineStruct) GetBodyMembers() []Member

GetBodyMembers returns all json fields

func (DefineStruct) GetFormMembers

func (t DefineStruct) GetFormMembers() []Member

GetFormMembers returns all form fields

func (DefineStruct) GetNonBodyMembers

func (t DefineStruct) GetNonBodyMembers() []Member

GetNonBodyMembers returns all have no tag fields

func (DefineStruct) Name

func (t DefineStruct) Name() string

Name returns a structure string, such as User

type Doc

type Doc []string

Doc describes document

type Group

type Group struct {
	Annotation Annotation
	Routes     []Route
}

Group defines a set of routing information

func (Group) GetAnnotation

func (g Group) GetAnnotation(key string) string

GetAnnotation returns the value by specified key from @server

type Import

type Import struct {
	Value string
}

Import describes api import

type Info

type Info struct {
	// Deprecated: use Properties instead
	Title string
	// Deprecated: use Properties instead
	Desc string
	// Deprecated: use Properties instead
	Version string
	// Deprecated: use Properties instead
	Author string
	// Deprecated: use Properties instead
	Email      string
	Properties map[string]string
}

Info describes info grammar block

type InterfaceType

type InterfaceType struct {
	RawName string
}

InterfaceType describes a interface for api

func (InterfaceType) Name

func (t InterfaceType) Name() string

Name returns a interface string, Its fixed value is interface{}

type MapType

type MapType struct {
	RawName string
	// only support the PrimitiveType
	Key string
	// it can be asserted as PrimitiveType: int、bool、
	// PointerType: *string、*User、
	// MapType: map[${PrimitiveType}]interface、
	// ArrayType:[]int、[]User、[]*User
	// InterfaceType: interface{}
	// Type
	Value Type
}

MapType describes a map for api

func (MapType) Name

func (t MapType) Name() string

Name returns a map string, such as map[string]int

type Member

type Member struct {
	Name string
	// 数据类型字面值,如:string、map[int]string、[]int64、[]*User
	Type    Type
	Tag     string
	Comment string
	// 成员头顶注释说明
	Docs     Doc
	IsInline bool
}

Member describes the field of a structure

func (Member) GetComment

func (m Member) GetComment() string

GetComment returns comment value of Member

func (Member) GetPropertyName

func (m Member) GetPropertyName() (string, error)

GetPropertyName returns json tag value

func (Member) IsBodyMember

func (m Member) IsBodyMember() bool

IsBodyMember returns true if contains json tag

func (Member) IsFormMember

func (m Member) IsFormMember() bool

IsFormMember returns true if contains form tag

func (Member) IsOmitEmpty

func (m Member) IsOmitEmpty() bool

IsOmitEmpty returns true if tag contains omitempty

func (Member) IsOptional

func (m Member) IsOptional() bool

IsOptional returns true if tag is optional

func (Member) Tags

func (m Member) Tags() []*Tag

Tags returns all tags in Member

type OriginType

type OriginType struct {
	RawName string
	Key     string
}

func (OriginType) Name

func (t OriginType) Name() string

type PointerType

type PointerType struct {
	RawName string
	Type    Type
}

PointerType describes a pointer for api

func (PointerType) Name

func (t PointerType) Name() string

Name returns a pointer string, such as *User

type PrimitiveType

type PrimitiveType struct {
	RawName string
}

PrimitiveType describes the basic golang type, such as bool,int32,int64, ...

func (PrimitiveType) Name

func (t PrimitiveType) Name() string

Name returns a basic string, such as int32,int64

type Route

type Route struct {
	AtServerAnnotation Annotation
	Method             string
	Path               string
	RequestType        Type
	ResponseType       Type
	Docs               Doc
	Handler            string
	AtDoc              AtDoc
}

Route describes api route

func (Route) GetAnnotation

func (r Route) GetAnnotation(key string) string

GetAnnotation returns the value by specified key from @server

func (Route) JoinedDoc

func (r Route) JoinedDoc() string

JoinedDoc joins comments and summary value in AtDoc

func (Route) RequestTypeName

func (r Route) RequestTypeName() string

RequestTypeName returns request type name of route

func (Route) ResponseTypeName

func (r Route) ResponseTypeName() string

ResponseTypeName returns response type name of route

type Service

type Service struct {
	Name   string
	Groups []Group
}

Service describes api service

func (Service) Routes

func (s Service) Routes() []Route

Routes returns all routes in api service

type Tag

type Tag struct {
	// Key is the tag key, such as json, xml, etc..
	// i.e: `json:"foo,omitempty". Here key is: "json"
	Key string

	// Name is a part of the value
	// i.e: `json:"foo,omitempty". Here name is: "foo"
	Name string

	// Options is a part of the value. It contains a slice of tag options i.e:
	// `json:"foo,omitempty". Here options is: ["omitempty"]
	Options []string
}

Tag defines a tag for structure filed

type Tags

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

Tags defines a slice for Tag

func Parse

func Parse(tag string) (*Tags, error)

Parse converts tag string into Tag

func (*Tags) Get

func (t *Tags) Get(key string) (*Tag, error)

Get gets tag value by specified key

func (*Tags) Keys

func (t *Tags) Keys() []string

Keys returns all keys in Tags

func (*Tags) Tags

func (t *Tags) Tags() []*Tag

Tags returns all tags in Tags

type Type

type Type interface {
	Name() string
}

Type defines api type

Jump to

Keyboard shortcuts

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