eosc

package module
v0.14.3 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2023 License: Apache-2.0 Imports: 18 Imported by: 99

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 added in v0.3.0

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

func Decompress added in v0.3.0

func Decompress(filePath string, dest string) error

Decompress 解压文件

func FileSha1 added in v0.3.0

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

func GetRealIP added in v0.1.1

func GetRealIP(r *http.Request) string

func Now added in v0.0.7

func Now() string

func ReadStringFromEntry added in v0.14.3

func ReadStringFromEntry(entry IEntry, key string) string

func SHA1 added in v0.3.0

func SHA1(data []byte) string

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

func SplitWorkerId added in v0.7.0

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

func ToWorkerId added in v0.1.0

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

func Version added in v0.3.0

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 added in v0.1.0

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

Deprecated: Use DriverConfig.ProtoReflect.Descriptor instead.

func (*DriverConfig) GetDesc added in v0.1.0

func (x *DriverConfig) GetDesc() string

func (*DriverConfig) GetId added in v0.1.0

func (x *DriverConfig) GetId() string

func (*DriverConfig) GetLabel added in v0.1.0

func (x *DriverConfig) GetLabel() string

func (*DriverConfig) GetName added in v0.1.0

func (x *DriverConfig) GetName() string

func (*DriverConfig) GetParams added in v0.1.0

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

func (*DriverConfig) ProtoMessage added in v0.1.0

func (*DriverConfig) ProtoMessage()

func (*DriverConfig) ProtoReflect added in v0.1.0

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

func (*DriverConfig) Reset added in v0.1.0

func (x *DriverConfig) Reset()

func (*DriverConfig) String added in v0.1.0

func (x *DriverConfig) String() string

type EoFiles added in v0.10.1

type EoFiles []GzipFile

type ExtenderBuilder added in v0.3.2

type ExtenderBuilder interface {
	Register(register IExtenderDriverRegister)
}

type ExtenderRegister added in v0.3.0

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

func NewExtenderRegister added in v0.3.0

func NewExtenderRegister() *ExtenderRegister

func (*ExtenderRegister) GetDriver added in v0.3.0

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

func (*ExtenderRegister) RegisterExtenderDriver added in v0.3.0

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

type ExtendersSettings added in v0.3.0

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

func (*ExtendersSettings) Descriptor deprecated added in v0.3.0

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

Deprecated: Use ExtendersSettings.ProtoReflect.Descriptor instead.

func (*ExtendersSettings) GetExtenders added in v0.3.0

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

func (*ExtendersSettings) ProtoMessage added in v0.3.0

func (*ExtendersSettings) ProtoMessage()

func (*ExtendersSettings) ProtoReflect added in v0.3.0

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

func (*ExtendersSettings) Reset added in v0.3.0

func (x *ExtendersSettings) Reset()

func (*ExtendersSettings) String added in v0.3.0

func (x *ExtendersSettings) String() string

type FormatterConfig added in v0.4.0

type FormatterConfig map[string][]string

type GzipFile added in v0.10.1

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

func (*GzipFile) DecodeData added in v0.10.1

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

type IDataMarshaller added in v0.1.0

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

type IEntry added in v0.4.0

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

type IExtenderConfigChecker added in v0.3.0

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

type IExtenderDriver added in v0.3.0

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

type IExtenderDriverFactory added in v0.3.0

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

type IExtenderDriverManager added in v0.3.1

type IExtenderDriverManager interface {
	IExtenderDriverRegister
}

type IExtenderDriverRegister added in v0.3.0

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

type IExtenderDrivers added in v0.3.0

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

type IFormatter added in v0.4.0

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

IFormatter format config

type IFormatterFactory added in v0.4.0

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

type IMetricEntry added in v0.10.1

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 added in v0.7.0

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 added in v0.7.0

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 added in v0.7.0

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 added in v0.7.0

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 added in v0.7.0

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 added in v0.5.0

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 added in v0.5.0

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

Deprecated: Use ProcessStatus.ProtoReflect.Descriptor instead.

func (*ProcessStatus) GetData added in v0.5.0

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

func (*ProcessStatus) GetMsg added in v0.5.0

func (x *ProcessStatus) GetMsg() string

func (*ProcessStatus) GetStatus added in v0.5.0

func (x *ProcessStatus) GetStatus() int32

func (*ProcessStatus) ProtoMessage added in v0.5.0

func (*ProcessStatus) ProtoMessage()

func (*ProcessStatus) ProtoReflect added in v0.5.0

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

func (*ProcessStatus) Reset added in v0.5.0

func (x *ProcessStatus) Reset()

func (*ProcessStatus) String added in v0.5.0

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 added in v0.1.0

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

Deprecated: Use ProfessionConfig.ProtoReflect.Descriptor instead.

func (*ProfessionConfig) GetAppendLabels added in v0.1.0

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

func (*ProfessionConfig) GetDependencies added in v0.1.0

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

func (*ProfessionConfig) GetDesc added in v0.1.0

func (x *ProfessionConfig) GetDesc() string

func (*ProfessionConfig) GetDrivers added in v0.1.0

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

func (*ProfessionConfig) GetLabel added in v0.1.0

func (x *ProfessionConfig) GetLabel() string

func (*ProfessionConfig) GetMod added in v0.3.0

func (*ProfessionConfig) GetName added in v0.1.0

func (x *ProfessionConfig) GetName() string

func (*ProfessionConfig) ProtoMessage added in v0.1.0

func (*ProfessionConfig) ProtoMessage()

func (*ProfessionConfig) ProtoReflect added in v0.1.0

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

func (*ProfessionConfig) Reset added in v0.1.0

func (x *ProfessionConfig) Reset()

func (*ProfessionConfig) String added in v0.1.0

func (x *ProfessionConfig) String() string

type ProfessionConfig_ProfessionMod added in v0.3.0

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

func (ProfessionConfig_ProfessionMod) Descriptor added in v0.3.0

func (ProfessionConfig_ProfessionMod) Enum added in v0.3.0

func (ProfessionConfig_ProfessionMod) EnumDescriptor deprecated added in v0.3.0

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

Deprecated: Use ProfessionConfig_ProfessionMod.Descriptor instead.

func (ProfessionConfig_ProfessionMod) Number added in v0.3.0

func (ProfessionConfig_ProfessionMod) String added in v0.3.0

func (ProfessionConfig_ProfessionMod) Type added in v0.3.0

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 added in v0.3.0

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

Deprecated: Use ProfessionConfigs.ProtoReflect.Descriptor instead.

func (*ProfessionConfigs) GetData added in v0.3.0

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

func (*ProfessionConfigs) ProtoMessage added in v0.3.0

func (*ProfessionConfigs) ProtoMessage()

func (*ProfessionConfigs) ProtoReflect added in v0.3.0

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

func (*ProfessionConfigs) Reset added in v0.3.0

func (x *ProfessionConfigs) Reset()

func (*ProfessionConfigs) String added in v0.3.0

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 added in v0.7.0

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

type TWorker added in v0.1.0

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 added in v0.8.0

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 added in v0.8.0

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

type WorkerConfig added in v0.3.0

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 added in v0.5.0

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

func (*WorkerConfig) Descriptor deprecated added in v0.3.0

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

Deprecated: Use WorkerConfig.ProtoReflect.Descriptor instead.

func (*WorkerConfig) GetBody added in v0.3.0

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

func (*WorkerConfig) GetCreate added in v0.3.0

func (x *WorkerConfig) GetCreate() string

func (*WorkerConfig) GetDescription added in v0.5.0

func (x *WorkerConfig) GetDescription() string

func (*WorkerConfig) GetDriver added in v0.3.0

func (x *WorkerConfig) GetDriver() string

func (*WorkerConfig) GetId added in v0.3.0

func (x *WorkerConfig) GetId() string

func (*WorkerConfig) GetName added in v0.3.0

func (x *WorkerConfig) GetName() string

func (*WorkerConfig) GetProfession added in v0.3.0

func (x *WorkerConfig) GetProfession() string

func (*WorkerConfig) GetUpdate added in v0.3.0

func (x *WorkerConfig) GetUpdate() string

func (*WorkerConfig) GetVersion added in v0.12.2

func (x *WorkerConfig) GetVersion() string

func (*WorkerConfig) ProtoMessage added in v0.3.0

func (*WorkerConfig) ProtoMessage()

func (*WorkerConfig) ProtoReflect added in v0.3.0

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

func (*WorkerConfig) Reset added in v0.3.0

func (x *WorkerConfig) Reset()

func (*WorkerConfig) String added in v0.3.0

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