Documentation
¶
Index ¶
- Constants
- Variables
- func IsValidArgName(s string) bool
- func ParseVarTypeExpr(schema *WebRPCSchema, expr string, vt *VarType) error
- type DataType
- type Import
- type Message
- type MessageField
- type MessageFieldMeta
- type MessageType
- type Method
- type MethodArgument
- type Parser
- type Reader
- type Service
- type VarListType
- type VarMapType
- type VarName
- type VarStructType
- type VarType
- type VarUserDefinedType
- type WebRPCSchema
- func (s *WebRPCSchema) GetMessageByName(name string) *Message
- func (s *WebRPCSchema) GetServiceByName(name string) *Service
- func (s *WebRPCSchema) GetStructByName(name string) *Message
- func (s *WebRPCSchema) HasFieldType(fieldType string) (bool, error)
- func (s *WebRPCSchema) SchemaHash() (string, error)
- func (s *WebRPCSchema) ToJSON(optIndent ...bool) (string, error)
- func (s *WebRPCSchema) Validate() error
Constants ¶
View Source
const (
VERSION = "v1" // todo rename to schema_version
)
Variables ¶
View Source
var DataTypeFromString = map[string]DataType{ "null": T_Null, "any": T_Any, "byte": T_Byte, "bool": T_Bool, "uint": T_Uint, "uint8": T_Uint8, "uint16": T_Uint16, "uint32": T_Uint32, "uint64": T_Uint64, "int": T_Int, "int8": T_Int8, "int16": T_Int16, "int32": T_Int32, "int64": T_Int64, "float32": T_Float32, "float64": T_Float64, "string": T_String, "timestamp": T_Timestamp, "map": T_Map, "[]": T_List, }
View Source
var DataTypeToString = map[DataType]string{ T_Null: "null", T_Any: "any", T_Byte: "byte", T_Bool: "bool", T_Uint: "uint", T_Uint8: "uint8", T_Uint16: "uint16", T_Uint32: "uint32", T_Uint64: "uint64", T_Int: "int", T_Int8: "int8", T_Int16: "int16", T_Int32: "int32", T_Int64: "int64", T_Float32: "float32", T_Float64: "float64", T_String: "string", T_Timestamp: "timestamp", T_Map: "map", T_List: "[]", }
View Source
var NameWhitelistRexp = regexp.MustCompile(`^[a-zA-Z]+[a-zA-Z0-9_]*$`)
Functions ¶
func IsValidArgName ¶
func ParseVarTypeExpr ¶
func ParseVarTypeExpr(schema *WebRPCSchema, expr string, vt *VarType) error
Types ¶
type DataType ¶
type DataType int
const ( T_Unknown DataType = iota T_Null T_Any T_Byte T_Bool T_Uint T_Uint8 T_Uint16 T_Uint32 T_Uint64 T_Int T_Int8 T_Int16 T_Int32 T_Int64 T_Float32 T_Float64 T_String T_Timestamp T_List T_Map T_Primitive T_Struct // aka, a reference to our own webrpc proto struct/message T_UserDefined //This defines the user created return type depending upon imports )
func (DataType) MarshalJSON ¶
func (*DataType) UnmarshalJSON ¶
type Message ¶
type Message struct { Name VarName `json:"name"` Type MessageType `json:"type"` Fields []*MessageField `json:"fields"` // EnumType determined for enum types during parsing time EnumType *VarType `json:"-"` }
func (*Message) Parse ¶
func (m *Message) Parse(schema *WebRPCSchema) error
type MessageField ¶
type MessageField struct { Name VarName `json:"name"` Type *VarType `json:"type"` Optional bool `json:"optional"` Value string `json:"value"` // used by enums // Meta store extra metadata on a field for plugins Meta []MessageFieldMeta `json:"meta"` }
type MessageFieldMeta ¶
type MessageFieldMeta map[string]interface{}
type MessageType ¶
type MessageType string // "enum" | "struct"
type Method ¶
type Method struct { Name VarName `json:"name"` StreamInput bool `json:"streamInput,omitempty"` StreamOutput bool `json:"streamOutput,omitempty"` Proxy bool `json:"-"` // TODO: actual implementation Inputs []*MethodArgument `json:"inputs"` Outputs []*MethodArgument `json:"outputs"` Service *Service `json:"-"` // denormalize/back-reference }
type MethodArgument ¶
type Parser ¶
type Parser interface {
Parse(schema *WebRPCSchema) error
}
type Service ¶
type Service struct { Name VarName `json:"name"` Methods []*Method `json:"methods"` Schema *WebRPCSchema `json:"-"` // denormalize/back-reference }
func (*Service) Parse ¶
func (s *Service) Parse(schema *WebRPCSchema) error
type VarListType ¶
type VarListType struct {
Elem *VarType
}
type VarMapType ¶
type VarName ¶
type VarName string
func (VarName) TitleDowncase ¶
TitleDowncase will downcase the first letter of a string, ie. convert a name form 'FirstName' to 'firstName'
func (VarName) TitleUpcase ¶
TitleUpcase will upcase the first letter of a string, ie. convert a name form 'firstName' to 'FirstName'
type VarStructType ¶
type VarType ¶
type VarType struct { Type DataType List *VarListType Map *VarMapType Struct *VarStructType UserDefined *VarUserDefinedType // contains filtered or unexported fields }
func (*VarType) MarshalJSON ¶
func (*VarType) Parse ¶
func (t *VarType) Parse(schema *WebRPCSchema) error
func (*VarType) UnmarshalJSON ¶
type VarUserDefinedType ¶
type VarUserDefinedType struct {
Name string
}
type WebRPCSchema ¶
type WebRPCSchema struct { WebRPCVersion string `json:"webrpc"` Name string `json:"name"` SchemaVersion string `json:"version"` SchemaType string `json:"schematype"` Imports []*Import `json:"imports"` Messages []*Message `json:"messages"` Services []*Service `json:"services"` }
schema of webrpc json file, and validations
func ParseSchemaJSON ¶
func ParseSchemaJSON(jsondata []byte) (*WebRPCSchema, error)
func (*WebRPCSchema) GetMessageByName ¶
func (s *WebRPCSchema) GetMessageByName(name string) *Message
func (*WebRPCSchema) GetServiceByName ¶
func (s *WebRPCSchema) GetServiceByName(name string) *Service
func (*WebRPCSchema) GetStructByName ¶
func (s *WebRPCSchema) GetStructByName(name string) *Message
Here Only updated the method name and kept the body same as GetMessageByName()
func (*WebRPCSchema) HasFieldType ¶
func (s *WebRPCSchema) HasFieldType(fieldType string) (bool, error)
func (*WebRPCSchema) SchemaHash ¶
func (s *WebRPCSchema) SchemaHash() (string, error)
func (*WebRPCSchema) Validate ¶
func (s *WebRPCSchema) Validate() error
Validate validates the schema through the AST, intended to be called after the json has been unmarshalled
Source Files
¶
Click to show internal directories.
Click to hide internal directories.