spec

package
v1.8.14 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2024 License: GPL-3.0 Imports: 6 Imported by: 7

Documentation

Index

Examples

Constants

View Source
const RoutePrefixKey = "prefix"

RoutePrefixKey is the prefix keyword for the routes.

Variables

View Source
var ErrMissingService = errors.New("missing service")

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      // Deprecated: useless expression
	Syntax  ApiSyntax // Deprecated: useless expression
	Imports []Import  // Deprecated: useless expression
	Types   []Type
	Service Service
}

ApiSpec describes an api file

func (*ApiSpec) Validate

func (s *ApiSpec) Validate() error

Validate validates Validate the integrity of the spec.

type ApiSyntax

type ApiSyntax struct {
	Version string
	Doc     Doc
	Comment Doc
}

ApiSyntax describes the syntax grammar

type ArrayType

type ArrayType struct {
	RawName string
	Value   Type
}

ArrayType describes a slice for api

func (ArrayType) Comments

func (t ArrayType) Comments() []string

Comments returns the comments of struct

func (ArrayType) Documents

func (t ArrayType) Documents() []string

Documents returns the documents of struct

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) Comments

func (t DefineStruct) Comments() []string

Comments returns the comments of struct

func (DefineStruct) Documents

func (t DefineStruct) Documents() []string

Documents returns the documents of struct

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) GetTagMembers

func (t DefineStruct) GetTagMembers(tagKey string) []Member

GetTagMembers returns all given key 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
	Doc     Doc
	Comment Doc
}

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 an interface for api

func (InterfaceType) Comments

func (t InterfaceType) Comments() []string

Comments returns the comments of struct

func (InterfaceType) Documents

func (t InterfaceType) Documents() []string

Documents returns the documents of struct

func (InterfaceType) Name

func (t InterfaceType) Name() string

Name returns an interface string, Its fixed value is any

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: any
	// Type
	Value Type
}

MapType describes a map for api

func (MapType) Comments

func (t MapType) Comments() []string

Comments returns the comments of struct

func (MapType) Documents

func (t MapType) Documents() []string

Documents returns the documents of struct

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) GetEnumOptions

func (m Member) GetEnumOptions() []string

GetEnumOptions return a slice contains all enumeration options

Example
package main

import (
	"fmt"

	"github.com/suyuan32/goctls/api/spec"
)

func main() {
	member := spec.Member{
		Tag: `json:"foo,options=foo|bar|options|123"`,
	}
	fmt.Println(member.GetEnumOptions())
}
Output:

[foo bar options 123]

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) IsTagMember

func (m Member) IsTagMember(tagKey string) bool

IsTagMember returns true if contains given tag

func (Member) Tags

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

Tags returns all tags in Member

type PointerType

type PointerType struct {
	RawName string
	Type    Type
}

PointerType describes a pointer for api

func (PointerType) Comments

func (t PointerType) Comments() []string

Comments returns the comments of struct

func (PointerType) Documents

func (t PointerType) Documents() []string

Documents returns the documents of struct

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) Comments

func (t PrimitiveType) Comments() []string

Comments returns the comments of struct

func (PrimitiveType) Documents

func (t PrimitiveType) Documents() []string

Documents returns the documents of struct

func (PrimitiveType) Name

func (t PrimitiveType) Name() string

Name returns a basic string, such as int32,int64

type Route

type Route struct {
	// Deprecated: Use Service AtServer instead.
	AtServerAnnotation Annotation
	Method             string
	Path               string
	RequestType        Type
	ResponseType       Type
	Docs               Doc
	Handler            string
	AtDoc              AtDoc
	HandlerDoc         Doc
	HandlerComment     Doc
	Doc                Doc
	Comment            Doc
}

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) JoinPrefix

func (s Service) JoinPrefix() 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
	Comments() []string
	Documents() []string
}

Type defines api type

Jump to

Keyboard shortcuts

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