You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-zero/tools/goctl/api/spec/spec.go

150 lines
3.0 KiB
Go

4 years ago
package spec
// RoutePrefixKey is the prefix keyword for the routes.
const RoutePrefixKey = "prefix"
4 years ago
type (
// Doc describes document
Doc []string
// Annotation defines key-value
4 years ago
Annotation struct {
Properties map[string]string
}
// ApiSyntax describes the syntax grammar
ApiSyntax struct {
Version string
Doc Doc
Comment Doc
4 years ago
}
// ApiSpec describes an api file
4 years ago
ApiSpec struct {
Info Info // Deprecated: useless expression
Syntax ApiSyntax // Deprecated: useless expression
Imports []Import // Deprecated: useless expression
4 years ago
Types []Type
Service Service
}
// Import describes api import
Import struct {
Value string
Doc Doc
Comment Doc
}
// Group defines a set of routing information
4 years ago
Group struct {
Annotation Annotation
Routes []Route
4 years ago
}
// Info describes info grammar block
4 years ago
Info struct {
// Deprecated: use Properties instead
Title string
// Deprecated: use Properties instead
Desc string
// Deprecated: use Properties instead
4 years ago
Version string
// Deprecated: use Properties instead
Author string
// Deprecated: use Properties instead
Email string
Properties map[string]string
4 years ago
}
// Member describes the field of a structure
4 years ago
Member struct {
Name string
4 years ago
// 数据类型字面值string、map[int]string、[]int64、[]*User
Type Type
Tag string
Comment string
4 years ago
// 成员头顶注释说明
Docs Doc
4 years ago
IsInline bool
}
// Route describes api route
4 years ago
Route struct {
// Deprecated: Use Service AtServer instead.
4 years ago
AtServerAnnotation Annotation
Method string
Path string
RequestType Type
ResponseType Type
Docs Doc
Handler string
AtDoc AtDoc
HandlerDoc Doc
HandlerComment Doc
Doc Doc
Comment Doc
4 years ago
}
// Service describes api service
4 years ago
Service struct {
Name string
Groups []Group
4 years ago
}
// Type defines api type
Type interface {
Name() string
Comments() []string
Documents() []string
4 years ago
}
// DefineStruct describes api structure
DefineStruct struct {
RawName string
Members []Member
Docs Doc
4 years ago
}
// PrimitiveType describes the basic golang type, such as bool,int32,int64, ...
PrimitiveType struct {
RawName string
4 years ago
}
// MapType describes a map for api
4 years ago
MapType struct {
RawName string
// only support the PrimitiveType
4 years ago
Key string
// it can be asserted as PrimitiveType: int、bool、
4 years ago
// PointerType: *string、*User、
// MapType: map[${PrimitiveType}]interface、
4 years ago
// ArrayType:[]int、[]User、[]*User
// InterfaceType: interface{}
// Type
Value Type
4 years ago
}
// ArrayType describes a slice for api
4 years ago
ArrayType struct {
RawName string
Value Type
4 years ago
}
// InterfaceType describes an interface for api
4 years ago
InterfaceType struct {
RawName string
4 years ago
}
// PointerType describes a pointer for api
PointerType struct {
RawName string
Type Type
4 years ago
}
// AtDoc describes a metadata for api grammar: @doc(...)
AtDoc struct {
Properties map[string]string
Text string
}
4 years ago
)