eosc

package module
v1.15.7 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

README

架构

image

抽象概念

profession

profession:职业,定义抽象分类

  1. profession定义名是唯一的,在框架中等于常量,不区分大小写, 只能用 字母、数字、下划线
    • 例如: upstream,service,router,plugin
  2. profession 定义列表字段,以及列表默认值
  3. 所有的配置项目都是profession实例,实例必须具有如下属性
    • id: uuid,全局唯一
    • name: name, 同profession内唯一
    • driver: 实现该实例的驱动名
  4. profession 实例需要实现销毁方法,框架会检查依赖关系并中断销毁

目前已知可能有的 profession 定义有

  • upstream
  • service
  • router
  • service discovery
  • auth
driver

driver:驱动,定义一个profession并实现能力

  1. driver需要定义一个render 给 admin ui 处理界面
  2. driver 实现检查 profession 的属性
  3. driver 实现通过 profession 的属性实例话运行的实例并完成运行状态的
  4. profession 实例的能力和属性由driver来定义
  5. driver 声明一个能力清单, 在实例依赖另一个实例时,通过查询对方能力来决定是否可用,并在执行时使用该能力

Documentation

Overview

Package eosc SPDX-License-Identifier: Apache-2.0

Index

Constants

View Source
const (
	EventInit  = "init"
	EventSet   = "set"
	EventReset = "reset"
	EventDel   = "delete"
)
View Source
const (
	NamespaceProfession = "profession"
	NamespaceWorker     = "worker"
	NamespaceExtender   = "extender"
	NamespaceVariable   = "variable"
)
View Source
const (
	//ProcessMaster master进程,守护进程
	ProcessMaster = "master"
	//ProcessWorker worker进程,负责网关主流程的执行
	ProcessWorker = "worker"
	//ProcessHelper helper进程,临时进程,用于检测插件下载操作
	ProcessHelper = "helper"
	//ProcessAdmin admin进程,缓存配置信息,常驻进程
	ProcessAdmin = "admin"
)

Variables

View Source
var (
	ErrorDriverNotExist             = errors.New("driver not exist")
	ErrorProfessionNotExist         = errors.New("profession not exist")
	ErrorNotAllowCreateForSingleton = errors.New("not allow create for singleton profession")
	ErrorWorkerNotExits             = errors.New("worker-data not exits")
	ErrorWorkerNotRunning           = errors.New("worker-data not running")
	ErrorRegisterConflict           = errors.New("conflict of register")
	ErrorNotGetSillForRequire       = errors.New("not get skill for require")
	ErrorTargetNotImplementSkill    = errors.New("require of skill not implement")
	ErrorParamsIsNil                = errors.New("params is nil")
	ErrorParamNotExist              = errors.New("not exist")
	ErrorStoreReadOnly              = errors.New("store read only")
	ErrorRequire                    = errors.New("require")
	ErrorProfessionDependencies     = errors.New("profession dependencies not complete")
	ErrorConfigIsNil                = errors.New("config is nil")
	ErrorConfigFieldUnknown         = errors.New("unknown type")
	ErrorConfigType                 = errors.New("error config type")
)
View Source
var (
	ProfessionConfig_ProfessionMod_name = map[int32]string{
		0: "Worker",
		1: "Singleton",
	}
	ProfessionConfig_ProfessionMod_value = map[string]int32{
		"Worker":    0,
		"Singleton": 1,
	}
)

Enum value maps for ProfessionConfig_ProfessionMod.

View Source
var (
	ErrorUnsupportedKind = errors.New("unsupported kind")
)
View Source
var File_message_proto protoreflect.FileDescriptor

Functions

func CreateFile

func CreateFile(name string) (*os.File, error)

func Decompress

func Decompress(filePath string, dest string) error

Decompress 解压文件

func FileSha1

func FileSha1(file *os.File, size int64) (string, error)

func GetRealIP

func GetRealIP(r *http.Request) string

func Now

func Now() string

func ReadStringFromEntry

func ReadStringFromEntry(entry IEntry, key string) string

func SHA1

func SHA1(data []byte) string

SHA1 生成SHA1加密后的16进制字符串

func SplitWorkerId

func SplitWorkerId(id string) (profession string, name string, success bool)

func ToWorkerId

func ToWorkerId(name, profession string) (string, bool)

func Version

func Version() string

Types

type DriverConfig

type DriverConfig struct {
	Id     string            `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
	Name   string            `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
	Label  string            `protobuf:"bytes,3,opt,name=label,proto3" json:"label,omitempty"`
	Desc   string            `protobuf:"bytes,4,opt,name=desc,proto3" json:"desc,omitempty"`
	Params map[string]string `` /* 153-byte string literal not displayed */
	// contains filtered or unexported fields
}

func (*DriverConfig) Descriptor deprecated

func (*DriverConfig) Descriptor() ([]byte, []int)

Deprecated: Use DriverConfig.ProtoReflect.Descriptor instead.

func (*DriverConfig) GetDesc

func (x *DriverConfig) GetDesc() string

func (*DriverConfig) GetId

func (x *DriverConfig) GetId() string

func (*DriverConfig) GetLabel

func (x *DriverConfig) GetLabel() string

func (*DriverConfig) GetName

func (x *DriverConfig) GetName() string

func (*DriverConfig) GetParams

func (x *DriverConfig) GetParams() map[string]string

func (*DriverConfig) ProtoMessage

func (*DriverConfig) ProtoMessage()

func (*DriverConfig) ProtoReflect

func (x *DriverConfig) ProtoReflect() protoreflect.Message

func (*DriverConfig) Reset

func (x *DriverConfig) Reset()

func (*DriverConfig) String

func (x *DriverConfig) String() string

type EoFiles

type EoFiles []GzipFile

type ExtenderBuilder

type ExtenderBuilder interface {
	Register(register IExtenderDriverRegister)
}

type ExtenderRegister

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

func NewExtenderRegister

func NewExtenderRegister() *ExtenderRegister

func (*ExtenderRegister) GetDriver

func (p *ExtenderRegister) GetDriver(name string) (IExtenderDriverFactory, bool)

func (*ExtenderRegister) RegisterExtenderDriver

func (p *ExtenderRegister) RegisterExtenderDriver(name string, factory IExtenderDriverFactory) error

type ExtendersSettings

type ExtendersSettings struct {
	Extenders map[string]string `` /* 159-byte string literal not displayed */
	// contains filtered or unexported fields
}

func (*ExtendersSettings) Descriptor deprecated

func (*ExtendersSettings) Descriptor() ([]byte, []int)

Deprecated: Use ExtendersSettings.ProtoReflect.Descriptor instead.

func (*ExtendersSettings) GetExtenders

func (x *ExtendersSettings) GetExtenders() map[string]string

func (*ExtendersSettings) ProtoMessage

func (*ExtendersSettings) ProtoMessage()

func (*ExtendersSettings) ProtoReflect

func (x *ExtendersSettings) ProtoReflect() protoreflect.Message

func (*ExtendersSettings) Reset

func (x *ExtendersSettings) Reset()

func (*ExtendersSettings) String

func (x *ExtendersSettings) String() string

type FormatterConfig

type FormatterConfig map[string][]string

type GzipFile

type GzipFile struct {
	Name string `json:"name"`
	Type string `json:"type"`
	Size int    `json:"size"`
	Data string `json:"data"`
}

func (*GzipFile) DecodeData

func (f *GzipFile) DecodeData() ([]byte, error)

type IDataMarshaller

type IDataMarshaller interface {
	Encode(startIndex int) ([]byte, []*os.File, error)
}

type IEntry

type IEntry interface {
	Read(pattern string) interface{}
	Children(child string) []IEntry
}

type IExtenderConfigChecker

type IExtenderConfigChecker interface {
	Check(v interface{}, workers map[RequireId]IWorker) error
}

type IExtenderDisable added in v1.15.3

type IExtenderDisable interface {
	Disable(v interface{}, workers map[RequireId]IWorker, name string) error
}

type IExtenderDriver

type IExtenderDriver interface {
	ConfigType() reflect.Type
	Create(id, name string, v interface{}, workers map[RequireId]IWorker) (IWorker, error)
}

type IExtenderDriverFactory

type IExtenderDriverFactory interface {
	Render() interface{}
	Create(profession string, name string, label string, desc string, params map[string]interface{}) (IExtenderDriver, error)
}

type IExtenderDriverManager

type IExtenderDriverManager interface {
	IExtenderDriverRegister
}

type IExtenderDriverRegister

type IExtenderDriverRegister interface {
	RegisterExtenderDriver(name string, factory IExtenderDriverFactory) error
}

type IExtenderDrivers

type IExtenderDrivers interface {
	GetDriver(name string) (IExtenderDriverFactory, bool)
}

type IFormatter

type IFormatter interface {
	Format(entry IEntry) []byte
}

IFormatter format config

type IFormatterFactory

type IFormatterFactory interface {
	Create(cfg FormatterConfig, extendCfg ...interface{}) (IFormatter, error)
}

type IMetricEntry

type IMetricEntry interface {
	Read(pattern string) string
	GetFloat(pattern string) (float64, bool)
	Children(child string) []IMetricEntry
}

type IProfession

type IProfession interface {
	Drivers() []*DriverConfig
	GetDriver(name string) (*DriverConfig, bool)
	HasDriver(name string) bool
	AppendAttr() []string
	Mod() ProfessionConfig_ProfessionMod
}

type IProfessions

type IProfessions interface {
	Set(name string, profession *ProfessionConfig) error
	Delete(name string) error
	Reset([]*ProfessionConfig)
	Names() []string
	GetProfession(name string) (IProfession, bool)
	All() []*ProfessionConfig
}

type IRegister

type IRegister[T any] interface {
	Register(name string, obj T, force bool) error
	Get(name string) (T, bool)
	Del(name string) (T, bool)
}

func NewRegister

func NewRegister[T any]() IRegister[T]

type IRequires

type IRequires interface {
	Set(id string, requires []string)
	Del(id string)
	RequireByCount(requireId string) int
	Requires(id string) []string
	RequireBy(requireId string) []string
}

type ISetting

type ISetting interface {
	ConfigType() reflect.Type
	Set(conf interface{}) (err error)
	Get() interface{}
	Mode() SettingMode
	Check(cfg interface{}) (profession, name, driver, desc string, err error)
	AllWorkers() []string
}

type ISettings

type ISettings interface {
	GetDriver(name string) (ISetting, bool)
	SettingWorker(name string, config []byte, variable IVariable) error
	Update(name string, variable IVariable) (err error)
	CheckVariable(name string, variable IVariable) (err error)
	GetConfig(name string) interface{}
}

type IVariable

type IVariable interface {
	SetByNamespace(namespace string, variables map[string]string) error
	GetByNamespace(namespace string) (map[string]string, bool)
	SetVariablesById(id string, variables []string)
	RemoveRequire(id string)
	Unmarshal(buf []byte, typ reflect.Type) (interface{}, []string, error)
	Check(namespace string, variables map[string]string) ([]string, IVariable, error)
	Get(id string) (string, bool)
	Len() int
}

type IWorker

type IWorker interface {
	Id() string
	Start() error
	Reset(conf interface{}, workers map[RequireId]IWorker) error
	Stop() error
	CheckSkill(skill string) bool
}

type IWorkerDestroy

type IWorkerDestroy interface {
	Destroy() error
}

type IWorkers

type IWorkers interface {
	Get(id string) (IWorker, bool)
}

type Item

type Item struct {
	Value string `json:"value"`
	Label string `json:"label"`
}

type ProcessStatus

type ProcessStatus struct {
	Status int32  `protobuf:"varint,1,opt,name=status,proto3" json:"status,omitempty"`
	Msg    string `protobuf:"bytes,2,opt,name=msg,proto3" json:"msg,omitempty"`
	Data   []byte `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"`
	// contains filtered or unexported fields
}

func (*ProcessStatus) Descriptor deprecated

func (*ProcessStatus) Descriptor() ([]byte, []int)

Deprecated: Use ProcessStatus.ProtoReflect.Descriptor instead.

func (*ProcessStatus) GetData

func (x *ProcessStatus) GetData() []byte

func (*ProcessStatus) GetMsg

func (x *ProcessStatus) GetMsg() string

func (*ProcessStatus) GetStatus

func (x *ProcessStatus) GetStatus() int32

func (*ProcessStatus) ProtoMessage

func (*ProcessStatus) ProtoMessage()

func (*ProcessStatus) ProtoReflect

func (x *ProcessStatus) ProtoReflect() protoreflect.Message

func (*ProcessStatus) Reset

func (x *ProcessStatus) Reset()

func (*ProcessStatus) String

func (x *ProcessStatus) String() string

type ProfessionConfig

type ProfessionConfig struct {
	Name         string                         `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`   //
	Label        string                         `protobuf:"bytes,2,opt,name=label,proto3" json:"label,omitempty"` //
	Desc         string                         `protobuf:"bytes,3,opt,name=desc,proto3" json:"desc,omitempty"`   //
	Dependencies []string                       `protobuf:"bytes,4,rep,name=dependencies,proto3" json:"dependencies,omitempty"`
	AppendLabels []string                       `protobuf:"bytes,5,rep,name=appendLabels,proto3" json:"appendLabels,omitempty"`
	Drivers      []*DriverConfig                `protobuf:"bytes,6,rep,name=drivers,proto3" json:"drivers,omitempty"`
	Mod          ProfessionConfig_ProfessionMod `protobuf:"varint,7,opt,name=mod,proto3,enum=service.ProfessionConfig_ProfessionMod" json:"mod,omitempty"`
	// contains filtered or unexported fields
}

func (*ProfessionConfig) Descriptor deprecated

func (*ProfessionConfig) Descriptor() ([]byte, []int)

Deprecated: Use ProfessionConfig.ProtoReflect.Descriptor instead.

func (*ProfessionConfig) GetAppendLabels

func (x *ProfessionConfig) GetAppendLabels() []string

func (*ProfessionConfig) GetDependencies

func (x *ProfessionConfig) GetDependencies() []string

func (*ProfessionConfig) GetDesc

func (x *ProfessionConfig) GetDesc() string

func (*ProfessionConfig) GetDrivers

func (x *ProfessionConfig) GetDrivers() []*DriverConfig

func (*ProfessionConfig) GetLabel

func (x *ProfessionConfig) GetLabel() string

func (*ProfessionConfig) GetMod

func (*ProfessionConfig) GetName

func (x *ProfessionConfig) GetName() string

func (*ProfessionConfig) ProtoMessage

func (*ProfessionConfig) ProtoMessage()

func (*ProfessionConfig) ProtoReflect

func (x *ProfessionConfig) ProtoReflect() protoreflect.Message

func (*ProfessionConfig) Reset

func (x *ProfessionConfig) Reset()

func (*ProfessionConfig) String

func (x *ProfessionConfig) String() string

type ProfessionConfig_ProfessionMod

type ProfessionConfig_ProfessionMod int32
const (
	ProfessionConfig_Worker    ProfessionConfig_ProfessionMod = 0
	ProfessionConfig_Singleton ProfessionConfig_ProfessionMod = 1
)

func (ProfessionConfig_ProfessionMod) Descriptor

func (ProfessionConfig_ProfessionMod) Enum

func (ProfessionConfig_ProfessionMod) EnumDescriptor deprecated

func (ProfessionConfig_ProfessionMod) EnumDescriptor() ([]byte, []int)

Deprecated: Use ProfessionConfig_ProfessionMod.Descriptor instead.

func (ProfessionConfig_ProfessionMod) Number

func (ProfessionConfig_ProfessionMod) String

func (ProfessionConfig_ProfessionMod) Type

type ProfessionConfigs

type ProfessionConfigs struct {
	Data []*ProfessionConfig `protobuf:"bytes,1,rep,name=data,proto3" json:"data,omitempty"`
	// contains filtered or unexported fields
}

func (*ProfessionConfigs) Descriptor deprecated

func (*ProfessionConfigs) Descriptor() ([]byte, []int)

Deprecated: Use ProfessionConfigs.ProtoReflect.Descriptor instead.

func (*ProfessionConfigs) GetData

func (x *ProfessionConfigs) GetData() []*ProfessionConfig

func (*ProfessionConfigs) ProtoMessage

func (*ProfessionConfigs) ProtoMessage()

func (*ProfessionConfigs) ProtoReflect

func (x *ProfessionConfigs) ProtoReflect() protoreflect.Message

func (*ProfessionConfigs) Reset

func (x *ProfessionConfigs) Reset()

func (*ProfessionConfigs) String

func (x *ProfessionConfigs) String() string

type Register

type Register[T any] struct {
	Untyped[string, T]
}

func (*Register[T]) Register

func (r *Register[T]) Register(name string, obj T, force bool) error

type RequireId

type RequireId string

type SettingMode

type SettingMode int
const (
	SettingModeReadonly SettingMode = iota
	SettingModeSingleton
	SettingModeBatch
)

type TWorker

type TWorker struct {
	Id         string      `json:"id,omitempty" yaml:"id"`
	Name       string      `json:"name,omitempty" yaml:"name"`
	Driver     string      `json:"driver,omitempty" yaml:"driver"`
	Profession string      `json:"profession,omitempty" yaml:"profession"`
	Create     time.Time   `json:"create" yaml:"create"`
	Update     time.Time   `json:"update" yaml:"update"`
	Data       interface{} `json:"data,omitempty" yaml:"data"`
}

type Untyped

type Untyped[K comparable, T any] interface {
	Set(k K, v T)
	Get(k K) (T, bool)
	Del(k K) (T, bool)
	Dels(k ...K) []T
	List() []T
	Keys() []K
	All() map[K]T
	Clone() Untyped[K, T]
	Count() int
}

func BuildUntyped

func BuildUntyped[K comparable, T any]() Untyped[K, T]

type WorkerConfig

type WorkerConfig struct {
	Id          string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
	Profession  string `protobuf:"bytes,2,opt,name=profession,proto3" json:"profession,omitempty"`
	Name        string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"`
	Driver      string `protobuf:"bytes,4,opt,name=driver,proto3" json:"driver,omitempty"`
	Create      string `protobuf:"bytes,5,opt,name=create,proto3" json:"create,omitempty"`
	Update      string `protobuf:"bytes,6,opt,name=update,proto3" json:"update,omitempty"`
	Body        []byte `protobuf:"bytes,7,opt,name=body,proto3" json:"body,omitempty"`
	Description string `protobuf:"bytes,8,opt,name=description,proto3" json:"description,omitempty"`
	Version     string `protobuf:"bytes,9,opt,name=version,proto3" json:"version,omitempty"`
	// contains filtered or unexported fields
}

func GenInitWorkerConfig

func GenInitWorkerConfig(ps []*ProfessionConfig) []*WorkerConfig

func (*WorkerConfig) Descriptor deprecated

func (*WorkerConfig) Descriptor() ([]byte, []int)

Deprecated: Use WorkerConfig.ProtoReflect.Descriptor instead.

func (*WorkerConfig) GetBody

func (x *WorkerConfig) GetBody() []byte

func (*WorkerConfig) GetCreate

func (x *WorkerConfig) GetCreate() string

func (*WorkerConfig) GetDescription

func (x *WorkerConfig) GetDescription() string

func (*WorkerConfig) GetDriver

func (x *WorkerConfig) GetDriver() string

func (*WorkerConfig) GetId

func (x *WorkerConfig) GetId() string

func (*WorkerConfig) GetName

func (x *WorkerConfig) GetName() string

func (*WorkerConfig) GetProfession

func (x *WorkerConfig) GetProfession() string

func (*WorkerConfig) GetUpdate

func (x *WorkerConfig) GetUpdate() string

func (*WorkerConfig) GetVersion

func (x *WorkerConfig) GetVersion() string

func (*WorkerConfig) ProtoMessage

func (*WorkerConfig) ProtoMessage()

func (*WorkerConfig) ProtoReflect

func (x *WorkerConfig) ProtoReflect() protoreflect.Message

func (*WorkerConfig) Reset

func (x *WorkerConfig) Reset()

func (*WorkerConfig) String

func (x *WorkerConfig) String() string

Directories

Path Synopsis
app
common
log
cli
* Copyright (c) 2021.
* Copyright (c) 2021.
schema
Package schema implements OpenAPI 3 compatible JSON Schema which can be generated from structs.
Package schema implements OpenAPI 3 compatible JSON Schema which can be generated from structs.
zip

Jump to

Keyboard shortcuts

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