eosc

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2021 License: GPL-3.0 Imports: 10 Imported by: 99

README

eosc

eosc

Documentation

Overview

SPDX-License-Identifier: Apache-2.0

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorDriverNotExist          = errors.New("driver not exist")
	ErrorProfessionNotExist      = errors.New("profession not exist")
	ErrorWorkerNotExits          = errors.New("worker not exits")
	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")
)

Functions

func CheckConfig

func CheckConfig(v interface{}, workers IWorkers) (map[RequireId]interface{}, error)

func Now added in v0.0.7

func Now() string

func RegisterProfessionDriver

func RegisterProfessionDriver(name string, factory IProfessionDriverFactory) error

func RegisterStoreDriver

func RegisterStoreDriver(name string, factory IStoreFactory)

func TypeName

func TypeName(t reflect.Type) string
func TypeNameOfValue(v reflect.Value) string {
	 if v.Kind() == reflect.Ptr{
	 	return TypeNameOfValue(v.Elem())
	 }
	 return TypeName(v.Type())
}

func TypeNameOf

func TypeNameOf(v interface{}) string

func WriteError

func WriteError(w http.ResponseWriter, resultErr error)

WriteError 返回错误

func WriteResult

func WriteResult(w http.ResponseWriter, code string, resultType, resultKey string, result interface{}, pageInfo *PageInfo)

WriteResult 写响应

func WriteResultInfo

func WriteResultInfo(w http.ResponseWriter, resultType string, resultKey string, result interface{})

WriteResultInfo 返回信息

func WriteResultInfoWithCode

func WriteResultInfoWithCode(w http.ResponseWriter, code string, resultType, resultKey string, result interface{})

WriteResultInfoWithCode 返回带状态信息的响应

func WriteResultInfoWithPage

func WriteResultInfoWithPage(w http.ResponseWriter, resultType, resultKey string, result interface{}, pageInfo *PageInfo)

WriteResultInfoWithPage 返回带页码信息的数据

func WriteSuccessInData

func WriteSuccessInData(w http.ResponseWriter, resultType, resultKey string, result interface{})

WriteSuccessInData 返回包含于data中的成功信息

func WriteSuccessNoData

func WriteSuccessNoData(w http.ResponseWriter, resultType string)

WriteSuccessNoData 返回无数据的成功信息

Types

type BytesData

type BytesData []byte

func MarshalBytes

func MarshalBytes(v interface{}) (BytesData, error)

func (BytesData) Marshal

func (b BytesData) Marshal() ([]byte, error)

func (BytesData) UnMarshal

func (b BytesData) UnMarshal(v interface{}) error

type DriverConfig

type DriverConfig struct {
	ID    string
	Name  string
	Label string
	Desc  string

	Params map[string]string
}

type DriverDetail

type DriverDetail struct {
	DriverInfo
	Extends ExtendInfo `json:"extends"`
}

type DriverInfo

type DriverInfo struct {
	Id         string            `json:"id"`
	Name       string            `json:"name"`
	Label      string            `json:"label"`
	Desc       string            `json:"desc"`
	Profession string            `json:"profession"`
	Params     map[string]string `json:"params"`
}

type ExtendInfo

type ExtendInfo struct {
	ID      string `json:"id"`
	Group   string `json:"group"`
	Project string `json:"project"`
	Name    string `json:"name"`
}

type IAdmin

type IAdmin interface {
	ListProfessions() []ProfessionInfo
	ListEmployees(profession string) ([]interface{}, error)
	ListEmployeeNames(profession string) ([]string, error)
	Update(profession, name, driver string, data IData) (*WorkerInfo, error)
	Delete(profession, name string) (*WorkerInfo, error)
	GetEmployee(profession, name string) (interface{}, error)
	Render(profession, driver string) (*Render, error)
	Renders(profession string) (map[string]*Render, error)
	Drivers(profession string) ([]DriverInfo, error)
	DriverInfo(profession, driver string) (DriverDetail, error)
	DriversItem(profession string) ([]Item, error)
	SearchBySkill(profession string, skill []string) ([]WorkerInfo, error)
}

type IAdminHandler

type IAdminHandler interface {
	GenHandler() (http.Handler, error)
}

type IData

type IData interface {
	UnMarshal(v interface{}) error
	Marshal() ([]byte, error)
}

type IDriverRegister

type IDriverRegister interface {
	RegisterProfessionDriver(name string, factory IProfessionDriverFactory) error
	GetProfessionDriver(name string) (IProfessionDriverFactory, bool)
}
var (
	DefaultProfessionDriverRegister IDriverRegister = NewProfessionDriverRegister()
)

type IProfession

type IProfession interface {
	Name() string
	Label() string
	Desc() string
	Dependencies() []string
	AppendLabels() []string

	CheckerConfig(driver string, cdata IData, workers IWorkers) error
	ChangeWorker(driver, id, name string, cdata IData, workers IWorkers) error
	// contains filtered or unexported methods
}

type IProfessionDriver

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

type IProfessionDriverCheckConfig added in v0.0.7

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

type IProfessionDriverFactory

type IProfessionDriverFactory interface {
	ExtendInfo() ExtendInfo
	Create(profession string, name string, label string, desc string, params map[string]string) (IProfessionDriver, error)
}

func GetProfessionDriver

func GetProfessionDriver(name string) (IProfessionDriverFactory, bool)

type IProfessionDriverInfo

type IProfessionDriverInfo interface {
	IProfessionDriver
	ExtendInfo() ExtendInfo
	DriverInfo() DriverInfo
}

type IProfessionDrivers

type IProfessionDrivers interface {
	Get(name string) (driver IProfessionDriverInfo, has bool)
	List() []IProfessionDriverInfo
	Keys() []string
}

func NewDrivers

func NewDrivers(drivers []*_TProfessionDriver) IProfessionDrivers

type IProfessions

type IProfessions interface {
	Infos() []ProfessionInfo
}

type IRegister

type IRegister interface {
	Register(name string, obj interface{}, force bool) error
	Get(name string) (interface{}, bool)
}

func NewRegister

func NewRegister() IRegister

type IRegisterData

type IRegisterData interface {
	Set(name string, v interface{})
	Get(name string) (interface{}, bool)
}

type IStore

type IStore interface {
	IStoreLock
	GetListener() IStoreListener
}

type IStoreEventHandler

type IStoreEventHandler interface {
	OnInit(vs []StoreValue) error
	OnDel(v StoreValue) error
	OnChange(v StoreValue) error
}

type IStoreFactory

type IStoreFactory interface {
	Create(params map[string]string) (IStore, error)
}

func GetStoreDriver

func GetStoreDriver(name string) (IStoreFactory, bool)

type IStoreListener

type IStoreListener interface {
	AddListen(h IStoreEventHandler) error
}

type IStoreLock

type IStoreLock interface {
	IStoreRW
	// 分布式时需要锁住全局
	ReadLock(ctx context.Context) (bool, error)
	ReadUnLock() error
	TryLock(ctx context.Context, expire int) (bool, error)
	UnLock() error
}

type IStoreRW

type IStoreRW interface {
	Initialization() error
	All() []StoreValue
	Get(id string) (StoreValue, bool)
	Set(v StoreValue) error
	Del(id string) error
	ReadOnly() bool
}

type IUntyped

type IUntyped interface {
	Set(name string, v interface{})
	Get(name string) (interface{}, bool)
	Del(name string) (interface{}, bool)
	List() []interface{}
	Keys() []string
	All() map[string]interface{}
	Clone() IUntyped
	Count() int
}

func NewUntyped

func NewUntyped() IUntyped

type IWorker

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

type IWorkers

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

func NewWorkers

func NewWorkers() IWorkers

type Item

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

type Marshaler

type Marshaler interface {
	Marshal() (string, error)
}

type PageInfo

type PageInfo struct {
	ItemNum  int `json:"itemNum,"`
	Page     int `json:"page,omitempty"`
	PageSize int `json:"pageSize,omitempty"`
	TotalNum int `json:"totalNum,"`
}

PageInfo 页码信息

func NewItemNum

func NewItemNum(num int) *PageInfo

NewItemNum 创建新的item

func (*PageInfo) SetPage

func (p *PageInfo) SetPage(page, size, total int) *PageInfo

SetPage 设置页码

type Profession

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

func (*Profession) AppendLabels

func (p *Profession) AppendLabels() []string

func (*Profession) ChangeWorker added in v0.0.7

func (p *Profession) ChangeWorker(driver, id, name string, cdata IData, workers IWorkers) error

func (*Profession) CheckerConfig added in v0.0.7

func (p *Profession) CheckerConfig(driver string, cdata IData, workers IWorkers) error

func (*Profession) Dependencies

func (p *Profession) Dependencies() []string

func (*Profession) Desc

func (p *Profession) Desc() string

func (*Profession) Label

func (p *Profession) Label() string

func (*Profession) Name

func (p *Profession) Name() string

type ProfessionConfig

type ProfessionConfig struct {
	Name         string
	Label        string
	Desc         string
	Dependencies []string
	AppendLabel  []string
	Drivers      []DriverConfig
}

type ProfessionConfigs

type ProfessionConfigs []ProfessionConfig

func (ProfessionConfigs) Gen

func (pcs ProfessionConfigs) Gen(driverRegister IDriverRegister, store IStore) (*Professions, error)

type ProfessionDriverRegister

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

func NewProfessionDriverRegister

func NewProfessionDriverRegister() *ProfessionDriverRegister

func (*ProfessionDriverRegister) GetProfessionDriver

func (p *ProfessionDriverRegister) GetProfessionDriver(name string) (IProfessionDriverFactory, bool)

func (*ProfessionDriverRegister) RegisterProfessionDriver

func (p *ProfessionDriverRegister) RegisterProfessionDriver(name string, factory IProfessionDriverFactory) error

type ProfessionDrivers

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

func (*ProfessionDrivers) Get

func (*ProfessionDrivers) Keys

func (d *ProfessionDrivers) Keys() []string

func (*ProfessionDrivers) List

type ProfessionInfo

type ProfessionInfo struct {
	Name         string       `json:"name"`
	LocalName    string       `json:"local_name"`
	Desc         string       `json:"desc"`
	Dependencies []string     `json:"dependencies"`
	AppendLabels []string     `json:"labels"`
	Drivers      []DriverInfo `json:"drivers"`
}

type ProfessionItem

type ProfessionItem struct {
}

type Professions

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

func (*Professions) Delete

func (ps *Professions) Delete(profession, name string) (*WorkerInfo, error)

func (*Professions) DriverInfo

func (ps *Professions) DriverInfo(profession, driver string) (DriverDetail, error)

func (*Professions) Drivers

func (ps *Professions) Drivers(profession string) ([]DriverInfo, error)

func (*Professions) DriversItem

func (ps *Professions) DriversItem(profession string) ([]Item, error)

func (*Professions) GetEmployee added in v0.0.7

func (ps *Professions) GetEmployee(profession, name string) (interface{}, error)

func (*Professions) Infos

func (ps *Professions) Infos() []ProfessionInfo

func (*Professions) ListEmployeeNames added in v0.0.7

func (ps *Professions) ListEmployeeNames(profession string) ([]string, error)

func (*Professions) ListEmployees

func (ps *Professions) ListEmployees(profession string) ([]interface{}, error)

ListEmployees

func (*Professions) ListProfessions

func (ps *Professions) ListProfessions() []ProfessionInfo

ListProfessions

func (*Professions) OnChange

func (ps *Professions) OnChange(v StoreValue) error

func (*Professions) OnDel

func (ps *Professions) OnDel(v StoreValue) error

func (*Professions) OnInit

func (ps *Professions) OnInit(vs []StoreValue) error

func (*Professions) Render

func (ps *Professions) Render(profession, driver string) (*Render, error)

func (*Professions) Renders

func (ps *Professions) Renders(profession string) (map[string]*Render, error)

func (*Professions) Save added in v0.0.7

func (ps *Professions) Save(v StoreValue) error

func (*Professions) SearchBySkill

func (ps *Professions) SearchBySkill(profession string, skill []string) ([]WorkerInfo, error)

func (*Professions) Update

func (ps *Professions) Update(profession, name, driver string, data IData) (*WorkerInfo, error)

type Register

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

func (*Register) Get

func (r *Register) Get(name string) (interface{}, bool)

func (*Register) Register

func (r *Register) Register(name string, obj interface{}, force bool) error

type Render

type Render struct {
}

func GenRender

func GenRender(t reflect.Type) *Render

type RequireId

type RequireId string

type StoreEventDispatcher

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

func NewStoreDispatcher

func NewStoreDispatcher() *StoreEventDispatcher

func (*StoreEventDispatcher) AddListen

func (*StoreEventDispatcher) DispatchChange

func (s *StoreEventDispatcher) DispatchChange(v StoreValue) error

func (*StoreEventDispatcher) DispatchDel

func (s *StoreEventDispatcher) DispatchDel(v StoreValue) error

func (*StoreEventDispatcher) DispatchInit

func (s *StoreEventDispatcher) DispatchInit(vs []StoreValue) error

type StoreValue

type StoreValue struct {
	Id         string
	Profession string
	Name       string
	Driver     string
	CreateTime string
	UpdateTime string
	IData      IData
	Sing       string
}

type WorkManager

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

func (*WorkManager) Del

func (wm *WorkManager) Del(id string) (IWorker, bool)

func (*WorkManager) Get

func (wm *WorkManager) Get(id string) (IWorker, bool)

func (*WorkManager) Set added in v0.0.7

func (wm *WorkManager) Set(id string, w IWorker)

type WorkerInfo

type WorkerInfo struct {
	Id     string `json:"id"`
	Name   string `json:"name"`
	Driver string `json:"driver"`
	Create string `json:"create_time"`
	Update string `json:"update_time"`
}

type Workers

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

func (*Workers) Del

func (ws *Workers) Del(id string) (*tWorker, bool)

func (*Workers) Get

func (ws *Workers) Get(id string) (*tWorker, bool)

func (*Workers) Set

func (ws *Workers) Set(id string, w IWorker)

Jump to

Keyboard shortcuts

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