common

package
v0.0.0-...-2db9d0a Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// pakcage version
	MajorVersion = 1
	MinorVersion = 1
	FixVersion   = 1
)
View Source
const (
	// package type definition
	Message     PackageType = 0x01
	Stream      PackageType = 0x02
	UserDefined PackageType = 0x04

	// flags
	FlagCompressed = 0x80

	// the len of magic sequence
	VersionSize      = 4
	PackageTypeSize  = 1
	PackageFlagsSize = 1
	PayloadLenSize   = 4
	HeaderSize       = VersionSize + PackageTypeSize + PackageFlagsSize + PayloadLenSize

	// filed offsets
	VersionOffset     = 0
	PackageTypeOffset = VersionSize
	FlagsOffset       = VersionSize + PackageTypeSize
	PayloadLenOffset  = VersionSize + PackageTypeSize + PackageFlagsSize
)

Variables

Functions

func GetNextId

func GetNextId() int

Types

type Agent

type Agent struct {
	Name        string `json:"name" yaml:"name"`
	Identifier  string `json:"identifier" yaml:"identifier" gorm:"primary_key"`
	Description string `json:"description" yaml:"description"`
}

type AgentConfig

type AgentConfig struct {
	Basic struct {
		Server  string `yaml:"server"`
		Port    int    `yaml:"port"`
		AgentId string `yaml:"agentId"`
	}
	Log   LogConfig
	Miscs struct {
		HttpTimeout int `yaml:"httpTimeout"`
	}
}

func GetAgentConf

func GetAgentConf() (*AgentConfig, bool)

type AgentManager

type AgentManager interface {
	List() ([]Agent, error)
	Add(node Agent) (*Agent, error)
	Update(node Agent) (*Agent, error)
	DeleteById(identifier string) error
}

type AgentMemoryManager

type AgentMemoryManager struct {
	Cache map[string]*Agent
}

func NewNodeMemCache

func NewNodeMemCache() *AgentMemoryManager

func (*AgentMemoryManager) Add

func (nc *AgentMemoryManager) Add(n Agent) (*Agent, error)

func (*AgentMemoryManager) DeleteById

func (nc *AgentMemoryManager) DeleteById(id string) error

func (*AgentMemoryManager) List

func (nc *AgentMemoryManager) List() ([]Agent, error)

func (*AgentMemoryManager) Update

func (nc *AgentMemoryManager) Update(n Agent) (*Agent, error)

type BasicCommand

type BasicCommand struct {
	Identifier string
	Sequence   int
	CType      CmdType
}

func (*BasicCommand) GetSequence

func (c *BasicCommand) GetSequence() int

func (*BasicCommand) Json

func (c *BasicCommand) Json() []byte

func (*BasicCommand) Validate

func (c *BasicCommand) Validate() *BasicResponse

Return a not empty response if the Identifier is empty

type BasicResponse

type BasicResponse struct {
	ResponseType ResponseType
	Identifier   string
	Sequence     int
	Code         ResponseCode
	Description  string
}

func (*BasicResponse) GetDescription

func (r *BasicResponse) GetDescription() string

func (*BasicResponse) GetResponseCode

func (r *BasicResponse) GetResponseCode() ResponseCode

func (*BasicResponse) GetSequence

func (r *BasicResponse) GetSequence() int

func (*BasicResponse) Json

func (r *BasicResponse) Json() []byte

func (*BasicResponse) Validate

func (r *BasicResponse) Validate() error

type CmdType

type CmdType int
const (
	ILLEGAL CmdType = iota
	REGISTER
	HTTP
)

type Command

type Command interface {
	GetSequence() int
	Json() []byte
	Validate() *BasicResponse
}

type HttpCommand

type HttpCommand struct {
	BasicCommand
	HttpRequest
}

func (*HttpCommand) Json

func (c *HttpCommand) Json() []byte

func (*HttpCommand) Validate

func (c *HttpCommand) Validate() *BasicResponse

Return a not empty response if the Identifier is empty

type HttpRequest

type HttpRequest struct {
	Schema   string
	Method   string
	Host     string
	Port     int
	BasePath string
	Path     string
	Headers  http.Header
	Body     []byte
}

func (*HttpRequest) ToString

func (request *HttpRequest) ToString() string

type HttpResponse

type HttpResponse struct {
	BasicResponse
	http.Header
	HttpResponseCode int
	HttpResponseText string
	Body             []byte
}

type LogConfig

type LogConfig struct {
	Debug      bool   `yaml:"debug"`
	ConsoleLog bool   `yaml:"consoleLog"`
	LogPath    string `yaml:"logPath"`
}

type MWMemoryCache

type MWMemoryCache struct {
	Cache map[string]Middlewares
}

func NewMWMemoryCache

func NewMWMemoryCache() *MWMemoryCache

func (*MWMemoryCache) Add

func (mc *MWMemoryCache) Add(nodeid string, m Middleware) (*Middleware, error)

func (*MWMemoryCache) DeleteByName

func (mc *MWMemoryCache) DeleteByName(nodeid string, name string) error

func (*MWMemoryCache) GetByName

func (mc *MWMemoryCache) GetByName(nodeid string, name string) (*Middleware, error)

func (*MWMemoryCache) List

func (mc *MWMemoryCache) List(nodeid string) ([]Middleware, error)

func (*MWMemoryCache) Update

func (mc *MWMemoryCache) Update(nodeid string, m Middleware) (*Middleware, error)

type Middleware

type Middleware struct {
	Name string `json:"name" yaml:"name"`
	Path string `json:"path" yaml:"path"`
	Port int    `json:"port" yaml:"port"`
}

type MiddlewareManager

type MiddlewareManager interface {
	List(nodeid string) (Middlewares, error)
	Add(nodeid string, middleware Middleware) (*Middleware, error)
	Update(nodeid string, middleware Middleware) (*Middleware, error)
	DeleteByName(nodeid string, name string) error
	GetByName(nodeid string, name string) error
}

type Middlewares

type Middlewares []Middleware

func (*Middlewares) GetMiddlewareByName

func (mws *Middlewares) GetMiddlewareByName(name string) *Middleware

type PackageHeader

type PackageHeader struct {
	// major_version: Version << 24
	// minor_version: Version << 16
	// fix_version: Version << 8
	// Version => {major_version} | {minor_version} | {fix_version}
	Version uint32

	// the package type
	// message package: 0x01
	// stream package: 0x02
	// user-defined package: 0x04
	PackageType PackageType

	// flags
	Flags uint8

	// payload length
	// the size of package payload
	PayloadLen uint32
}

func NewPackageHeader

func NewPackageHeader(packageType PackageType) *PackageHeader

new package

func (*PackageHeader) GetFlags

func (h *PackageHeader) GetFlags() uint8

get package flags

func (*PackageHeader) GetPackageType

func (h *PackageHeader) GetPackageType() PackageType

get package type

func (*PackageHeader) GetPayloadLen

func (h *PackageHeader) GetPayloadLen() uint32

get payload len of package

func (*PackageHeader) GetVersion

func (h *PackageHeader) GetVersion() uint32

get version

func (*PackageHeader) Pack

func (h *PackageHeader) Pack(buffer *[]byte)

do packing

func (*PackageHeader) SetFlags

func (h *PackageHeader) SetFlags(flags uint8) *PackageHeader

set package flags

func (*PackageHeader) SetPackageType

func (h *PackageHeader) SetPackageType(packageType PackageType) *PackageHeader

set package type

func (*PackageHeader) SetPayloadLen

func (h *PackageHeader) SetPayloadLen(payloadLen uint32) *PackageHeader

set payload len

func (*PackageHeader) SetVersion

func (h *PackageHeader) SetVersion(version uint32) *PackageHeader

set version

func (*PackageHeader) Unpack

func (h *PackageHeader) Unpack(header []byte)

do unpacking

type PackageType

type PackageType uint8

type QConnectionManager

type QConnectionManager map[string]*QuicConnection

func GetManager

func GetManager() QConnectionManager

func (QConnectionManager) AddConn

func (qcm QConnectionManager) AddConn(id string, qc *QuicConnection)

func (QConnectionManager) GetConn

func (qcm QConnectionManager) GetConn(id string) *QuicConnection

func (QConnectionManager) RemoveConn

func (qcm QConnectionManager) RemoveConn(id string)

type QuicConnection

type QuicConnection struct {
	Session quic.Session
	Stream  quic.Stream

	Cancel context.CancelFunc
	// contains filtered or unexported fields
}

func (*QuicConnection) ListenToClient

func (qc *QuicConnection) ListenToClient()

func (*QuicConnection) SendCommand

func (qc *QuicConnection) SendCommand(cmd Command) (Response, error)

type Reader

type Reader struct {
	Reader io.Reader
}

func NewReader

func NewReader(r io.Reader) *Reader

func (*Reader) Read

func (r *Reader) Read() ([]byte, error)

Read message raw data from reader steps: 1)read the package header 2)unpack the package header and get the payload length 3)read the payload

type Response

type Response interface {
	GetSequence() int
	GetResponseCode() ResponseCode
	GetDescription() string
	Json() []byte
	Validate() error
}

type ResponseCode

type ResponseCode int
const (
	OK ResponseCode = iota
	BAD_REQUEST
	ERROR_FOUND
)

type ResponseType

type ResponseType int
const (
	BASIC_R ResponseType = iota
	HTTP_R
)

type ServerConfig

type ServerConfig struct {
	Basic struct {
		BindAddr string `yaml:"bindAddr"`
		BindPort int    `yaml:"bindPort"`
	}
	Log  LogConfig
	Rest struct {
		RestBindAddr string `yaml:"restBindAddr"`
		RestBindPort int    `yaml:"restBindPort"`
		EnableRest   bool   `yaml:"enableRest"`
	}
}

func GetSrvConf

func GetSrvConf() (*ServerConfig, bool)

type Writer

type Writer struct {
	Writer io.Writer
}

func NewWriter

func NewWriter(w io.Writer) *Writer

new Writer instance

func (*Writer) Write

func (w *Writer) Write(data []byte) (int, error)

Write message raw data steps: 1) packer the package header 2) write header 3) write message raw data

Jump to

Keyboard shortcuts

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