chef

package module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2022 License: MIT Imports: 20 Imported by: 16

README

chef

Chefs.go chef

Documentation

Index

Constants

View Source
const (
	JSON   = "json"
	XML    = "xml"
	GOB    = "gob"
	TOML   = "toml"
	DIGIT  = "digit"
	DIGITS = "digits"
	TEXT   = "text"
	TEXTS  = "text"
)
View Source
const (
	CHEF    = "chef"
	CHEFSGO = "Chefs.go"

	DEFAULT = "default"

	UTF8   = "utf-8"
	GB2312 = "gb2312"
	GBK    = "gbk"

	INVOKE_TYPE = "*t*"
)
View Source
const (
	START = "start"
	STOP  = "stop"
)

Variables

View Source
var (
	OK      = Result(0, "ok", "成功")
	Fail    = Result(1, "fail", "失败")
	Retry   = Result(2, "retry", "重试")
	Invalid = Result(3, "invalid", "无效请求或数据")
	Nothing = Result(4, "nothing", "无效对象")

	Unsigned = Result(5, "unsigned", "无权访问")
	Unauthed = Result(6, "unauthed", "无权访问")
)

Functions

func Arguments

func Arguments(name string, extends ...Vars) Vars

方法参数

func CloseMeta

func CloseMeta(meta *Meta)

CloseMeta 所有携带Meta的Context,必须在执行完成后 调用 CloseMeta 来给meta做收尾的工作,主要是删除临时文件,关闭连接之类的

func Codecs

func Codecs() map[string]Codec

func Configure

func Configure(cfg Map)

Configure 开放修改默认配置 比如,在代码中就可以设置一些默认配置 这样就可以最大化的减少配置文件的依赖

func Decode

func Decode(name string, data Any, obj Any) (Any, error)

func Decrypt

func Decrypt(name string, obj Any) (Any, error)

func DecryptDIGIT

func DecryptDIGIT(s string) (int64, error)

DecryptDigit 解码数字

func DecryptDIGITS

func DecryptDIGITS(s string) ([]int64, error)

DecryptDigits 解码数字数组

func DecryptTEXT

func DecryptTEXT(s string) (string, error)

DecryptTEXT 解码文本

func DecryptTEXTS

func DecryptTEXTS(s string) ([]string, error)

DecryptTEXTS 解码文本数组

func Define

func Define(tttt string, require bool, def Any, name string, extends ...Any) Var

定义Var def表示默认值,不写请传nil

func Developing

func Developing() bool

func DigitAlphabet

func DigitAlphabet() string

func DigitLength

func DigitLength() int

func DigitSalt

func DigitSalt() string

func Encode

func Encode(name string, v Any) (Any, error)

func Encrypt

func Encrypt(name string, obj Any) (string, error)

func EncryptDIGIT

func EncryptDIGIT(n int64) (string, error)

EncryptDIGIT

func EncryptDIGITS

func EncryptDIGITS(ns []int64) (string, error)

EncryptDIGITS

func EncryptTEXT

func EncryptTEXT(n string) (string, error)

EncryptTEXT 加密文本

func EncryptTEXTS

func EncryptTEXTS(ns []string) (string, error)

TextsEncrypt 文本数组加密

func Execute

func Execute(name string, values ...Any) (Map, Res)

直接执行,同步,本地

func Expressions

func Expressions(name string, defs ...string) []string

Expressions 获取正则的表达式

func Extension

func Extension(mime string, defs ...string) string

Extension 按MIMEType获取扩展名

func Generate

func Generate(prefixs ...string) string

Unique 雪花ID 转数字加密

func Go

func Go(args ...string)

Go 直接开跑

func Identify

func Identify(role string, versions ...string)

Identify 声明当前节点的身份和版本 role 当前节点的角色 version 编译的版本,建议每次发布时更新版本

func Languages

func Languages() map[string]Language

func Library

func Library(name string, bases ...int) *group

func Mapping

func Mapping(config Vars, data Map, value Map, argn bool, pass bool, zones ...*time.Location) Res

func Marshal

func Marshal(name string, obj Any) ([]byte, error)

func MarshalGOB

func MarshalGOB(v Any) ([]byte, error)

GOBMarshal

func MarshalJSON

func MarshalJSON(v Any) ([]byte, error)

MarshalJSON

func MarshalTOML

func MarshalTOML(v Any) ([]byte, error)

MarshalTOML

func MarshalXML

func MarshalXML(v Any) ([]byte, error)

MarshalXML

func Match

func Match(regular, value string) bool

Match 正则做匹配校验

func Mimetype

func Mimetype(ext string, defs ...string) string

Mimetype 按扩展名获取 MIME 中的 类型

func Mode

func Mode() env

func Module

func Module(name string, bases ...int) *group

func Name

func Name() string

func Precision added in v0.1.4

func Precision(f float64, prec int, rounds ...bool) float64

保留小数位

func Production

func Production() bool

func Ready

func Ready()

Ready 准备好各模块 当你需要写一个临时程序,但是又需要使用程序里的代码 比如,导入老数据,整理文件或是数据,临时的采集程序等等 就可以在临时代码中,调用chef.Ready(),然后做你需要做的事情

func Register

func Register(cfgs ...Any)

Register 注册各种内容

func Result

func Result(code int, state string, text string, overrides ...bool) Res

Result 定义一个result,并自动注册state state 表示状态key text 表示状态对应的默认文案

func Results added in v0.1.2

func Results(langs ...string) map[State]string

func Role

func Role() string

func Sequence

func Sequence() int64

Sequence 雪花ID

func Setting

func Setting() Map

func Sign

func Sign(auth bool, payload Map, ends ...time.Duration) string

Sign 生成签名 可以用在一些批量生成的场景

func Site added in v0.1.1

func Site(name string, bases ...int) *group

func StateCode

func StateCode(name string, defs ...int) int

StateCode 返回状态码

func String

func String(lang, name string, args ...Any) string

String 获取多语言字串

func TempDir

func TempDir(patterns ...string) (string, error)

func TempFile

func TempFile(patterns ...string) (*os.File, error)

func Testing

func Testing() bool

func TextAlphabet

func TextAlphabet() string

func Toggle added in v0.1.3

func Toggle(name string, values ...Any)

func Types

func Types() map[string]Type

Types 获取所有类型定义

func Unmarshal

func Unmarshal(name string, data []byte, obj Any) error

func UnmarshalGOB

func UnmarshalGOB(d []byte, v Any) error

UnmarshalGOB

func UnmarshalJSON

func UnmarshalJSON(d []byte, v Any) error

UnmarshalJSON

func UnmarshalTOML

func UnmarshalTOML(d []byte, v Any) error

UnmarshalTOML

func UnmarshalXML

func UnmarshalXML(d []byte, v Any) error

XMLUnmarshal

func VarExtend

func VarExtend(config Var, extends ...Any) Var

func VarsExtend

func VarsExtend(config Vars, extends ...Vars) Vars

func Version

func Version() string

Types

type BusBridge

type BusBridge interface {
	Request(meta Metadata, timeout time.Duration) (*Echo, error)
}

type Codec

type Codec struct {
	// Name 名称
	Name string
	// Text 说明
	Text string
	// Alias 别名
	Alias []string
	// Encode 编码方法
	Encode EncodeFunc
	// Decode 解码方法
	Decode DecodeFunc
}

type Context

type Context struct {
	*Meta
	Name    string
	Config  Method
	Setting Map

	Value Map
	Args  Map
}

type DecodeFunc

type DecodeFunc func(d Any, v Any) (Any, error)

type Echo

type Echo struct {
	Code  int    `json:"c,omitempty"`
	Text  string `json:"s,omitempty"`
	Args  Vars   `json:"a,omitempty"`
	Data  Map    `json:"d,omitempty"`
	Value []byte `json:"v,omitempty"`
	Type  string `json:"t,omitempty"`
}

type EncodeFunc

type EncodeFunc func(v Any) (Any, error)

type Language

type Language struct {
	// Name 语言名称
	Name string
	// Text 语言说明
	Text string
	// Accepts 匹配的语言
	// 比如,znCN, zh, zh-CN 等自动匹配
	Accepts []string
	// Strings 当前语言是字符串列表
	Strings Strings
}

type Logic

type Logic struct {
	Name    string
	Setting Map
	// contains filtered or unexported fields
}

func (*Logic) Invoke

func (lgc *Logic) Invoke(name string, values ...Any) Map

func (*Logic) Invoked

func (logic *Logic) Invoked(name string, values ...Any) bool

func (*Logic) Invokee

func (logic *Logic) Invokee(name string, values ...Any) float64

func (*Logic) Invoker

func (logic *Logic) Invoker(name string, values ...Any) (Map, []Map)

gob之后,不需要再定义data模型

func (*Logic) Invokes

func (logic *Logic) Invokes(name string, values ...Any) []Map

func (*Logic) Invoking

func (logic *Logic) Invoking(name string, offset, limit int64, values ...Any) (int64, []Map)

type Meta

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

func (*Meta) Authed

func (meta *Meta) Authed() bool

是否通过验证

func (*Meta) Id

func (meta *Meta) Id() string

Id 是token的ID,类似与 sessionId

func (*Meta) Invoke

func (meta *Meta) Invoke(name string, values ...Any) Map

------- 服务调用 -----------------

func (*Meta) Invoked

func (meta *Meta) Invoked(name string, values ...Any) bool

func (*Meta) Invokee

func (meta *Meta) Invokee(name string, values ...Any) float64

func (*Meta) Invoker

func (meta *Meta) Invoker(name string, values ...Any) (Map, []Map)

集群后,此方法data不好定义, 使用gob编码内容后,就不再需要定义data了

func (*Meta) Invokes

func (meta *Meta) Invokes(name string, values ...Any) []Map

func (*Meta) Invoking

func (meta *Meta) Invoking(name string, offset, limit int64, values ...Any) (int64, []Map)

func (*Meta) Language

func (meta *Meta) Language(langs ...string) string

Language 设置的时候,做一下langs的匹配

func (*Meta) Logic

func (meta *Meta) Logic(name string, settings ...Map) *Logic

func (*Meta) Metadata

func (meta *Meta) Metadata(datas ...Metadata) Metadata

func (*Meta) Payload

func (meta *Meta) Payload() Map

Payload Token携带的负载

func (*Meta) Result

func (meta *Meta) Result(res ...Res) Res

返回最后的错误信息 获取操作结果

func (*Meta) Retries

func (meta *Meta) Retries() int

Retries 重试次数 0 为还没重试

func (*Meta) Sign

func (meta *Meta) Sign(auth bool, payload Map, ends ...time.Duration) string

Sign 生成签名 此方法不会更新当前上下文中的token和verify 可以用在一些批量生成的场景

func (*Meta) Signed

func (meta *Meta) Signed() bool

Tokenized 是否有合法的token

func (*Meta) String

func (meta *Meta) String(key string, args ...Any) string

获取langString

func (*Meta) TempDir

func (meta *Meta) TempDir(patterns ...string) (string, error)

func (*Meta) TempFile

func (meta *Meta) TempFile(patterns ...string) (*os.File, error)

生成临时文件

func (*Meta) Timezone

func (meta *Meta) Timezone(zones ...*time.Location) *time.Location

Timezone 获取当前时区

func (*Meta) Token

func (meta *Meta) Token(tokens ...string) string

Token 令牌

func (*Meta) Trace

func (meta *Meta) Trace(traces ...string) string

Trace 追踪ID

func (*Meta) Verify

func (meta *Meta) Verify(token string) error

Verify 验证签名

type Metadata

type Metadata struct {
	Name     string `json:"n,omitempty"`
	Payload  Map    `json:"p,omitempty"`
	Retries  int    `json:"r,omitempty"`
	Language string `json:"l,omitempty"`
	Timezone int    `json:"z,omitempty"`
	Token    string `json:"t,omitempty"`
	Trace    string `json:"i,omitempty"`
}

type Method

type Method struct {
	Name     string   `json:"name"`
	Text     string   `json:"desc"`
	Alias    []string `json:"-"`
	Nullable bool     `json:"null"`
	Args     Vars     `json:"args"`
	Data     Vars     `json:"data"`
	Setting  Map      `json:"-"`
	Coding   bool     `json:"-"`
	Action   Any      `json:"-"`

	Sign bool `json:"sign"`
	Auth bool `json:"auth"`
}

type Mime

type Mime []string

MIME mimetype集合

type Mimes

type Mimes map[string]Mime

type Regular

type Regular []string

Regular 正则表达式,方便注册

type Regulars

type Regulars map[string]Regular

type Service

type Service struct {
	Name     string   `json:"name"`
	Text     string   `json:"desc"`
	Alias    []string `json:"-"`
	Nullable bool     `json:"null"`
	Args     Vars     `json:"args"`
	Data     Vars     `json:"data"`
	Setting  Map      `json:"-"`
	Coding   bool     `json:"-"`
	Action   Any      `json:"-"`

	Sign bool `json:"token"`
	Auth bool `json:"auth"`
}

type State

type State int

State 状态定义,方便注册

type States

type States map[string]State

type Strings

type Strings map[string]string

多语言配置

type Token

type Token struct {
	Header  tokenHeader
	Payload Map
}

func Verify

func Verify(token string) (*Token, error)

Verify

type Trigger

type Trigger struct {
	Name     string   `json:"name"`
	Text     string   `json:"desc"`
	Alias    []string `json:"-"`
	Nullable bool     `json:"null"`
	Args     Vars     `json:"args"`
	Data     Vars     `json:"data"`
	Setting  Map      `json:"-"`
	Coding   bool     `json:"-"`
	Action   Any      `json:"-"`

	Sign bool `json:"token"`
	Auth bool `json:"auth"`
}

type Type

type Type struct {
	// Name 类型名称
	Name string

	// Text 类型说明
	Text string

	// Alias 类型别名
	Alias []string

	// Valid 类型验证方法
	Valid TypeValidFunc

	// Value 值包装方法
	Value TypeValueFunc
}

Type 类型定义

type TypeValidFunc

type TypeValidFunc func(Any, Var) bool

type TypeValueFunc

type TypeValueFunc func(Any, Var) Any

Jump to

Keyboard shortcuts

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