app

package
v0.0.0-...-7f62477 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2023 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvModule    = "MODULE"
	EnvWorkPath  = "WORK_PATH"
	EnvProtoc    = "PROTOC"
	EnvProtoPath = "PROTO_PATH"
	EnvTplPath   = "TPL_PATH"
)
View Source
const (
	HeaderErrCode = "X-ErrCode"
	HeaderErrMsg  = "X-ErrMsg"
)

Variables

View Source
var ErrConfigNotFound = errorx.New("config not found")

Functions

func CliCall

func CliCall(ctx Ctx, service, path string, req, rsp proto.Message) error

func CmdExecute

func CmdExecute(ctx Ctx, cfg Cfg, executors []Executor, rpcs []RpcDoc) error

func Env

func Env(key string) string

func Envs

func Envs() map[string]string

func Init

func Init(project, service string, isCmd bool)

func LoadEnv

func LoadEnv(prefix string)

func SetDefApp

func SetDefApp(app *App)

func SvrRun

func SvrRun(ctx Ctx, cfg Cfg, handlers []Handler, rpcs []RpcDoc) error

func TestCall

func TestCall(rpcFn interface{}, ctx Ctx, req proto.Message, init ...func()) (
	proto.Message, error)

func TestCallByJson

func TestCallByJson(rpcFn interface{}, ctx Ctx, jsonStr string, init ...func()) (
	proto.Message, error)

func TestGetReq

func TestGetReq(req proto.Message, str string, init ...func()) proto.Message

Types

type Addr

type Addr struct {
	Name string   `json:"name"`
	Addr []string `json:"addr"`
}

func NewAddr

func NewAddr(name, addr string) *Addr

func (*Addr) BuildPaths

func (a *Addr) BuildPaths(path string) []string

func (*Addr) GetAddr

func (a *Addr) GetAddr() string

func (*Addr) GetAddress

func (a *Addr) GetAddress() string

func (*Addr) GetNetwork

func (a *Addr) GetNetwork() string

func (*Addr) SetAddr

func (a *Addr) SetAddr(addr string)

type Addrs

type Addrs struct {
	*config.Config
	Services map[string]*Addr `json:"services"`
}

func NewAddrs

func NewAddrs(c *config.Config) *Addrs

func (*Addrs) Add

func (a *Addrs) Add(addr *Addr) error

func (*Addrs) Remove

func (a *Addrs) Remove(addr *Addr) error

type App

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

func NewApp

func NewApp(cfg Cfg, rpcs []RpcDoc) *App

func (*App) Run

func (a *App) Run(ctx Ctx) error

type Cfg

type Cfg struct {
	Name      string
	Addr      string
	Path      string
	AddrsFile string
	// contains filtered or unexported fields
}

func NewCfg

func NewCfg(cfg Cfg) (*Cfg, error)

func (*Cfg) Get

func (c *Cfg) Get(key string, def interface{}) interface{}

func (*Cfg) GetJsonData

func (c *Cfg) GetJsonData(key string, out interface{}) error

func (*Cfg) GetStr

func (c *Cfg) GetStr(key string, def string) string

type Cli

type Cli struct {
	*Cfg
	*Addrs
}

func NewCli

func NewCli(cfg *Cfg, addrs *Addrs) *Cli

func (*Cli) Call

func (c *Cli) Call(ctx Ctx, service, path string, req, rsp proto.Message) error

type Cmd

type Cmd struct {
	*Cfg
	// contains filtered or unexported fields
}

func NewCmd

func NewCmd(cfg *Cfg, rpcs map[string]*Rpc) *Cmd

func (*Cmd) Execute

func (c *Cmd) Execute(_ Ctx) error

func (*Cmd) RegisterExecutors

func (c *Cmd) RegisterExecutors(executors []Executor)

type CmdCtx

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

func NewCmdCtx

func NewCmdCtx() *CmdCtx

func (*CmdCtx) GetInstant

func (ctx *CmdCtx) GetInstant() interface{}

func (*CmdCtx) GetReqId

func (ctx *CmdCtx) GetReqId() string

func (*CmdCtx) MustParse

func (ctx *CmdCtx) MustParse(req proto.Message) proto.Message

type Ctx

type Ctx interface {
	context.IContext
	GetInstant() interface{}
}

type ExecHandler

type ExecHandler func(ctx Ctx) (proto.Message, error)

type Executor

type Executor struct {
	Path        string
	ExecHandler ExecHandler
}

type Handler

type Handler struct {
	Path   string
	Handle interface{}
	// contains filtered or unexported fields
}

type Rpc

type Rpc struct {
	Path string
	Req  reflect.Type
	Rsp  reflect.Type
}

func (*Rpc) Example

func (r *Rpc) Example()

type RpcCtx

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

func NewRpcCtx

func NewRpcCtx() *RpcCtx

func (*RpcCtx) GetInstant

func (ctx *RpcCtx) GetInstant() interface{}

func (*RpcCtx) GetReqId

func (ctx *RpcCtx) GetReqId() string

type RpcDoc

type RpcDoc struct {
	Path string
	Func interface{}
}

type Svr

type Svr struct {
	*Cfg
	*Addrs
	// contains filtered or unexported fields
}

func NewSvr

func NewSvr(cfg *Cfg, addrs *Addrs, rpcs map[string]*Rpc) *Svr

func (*Svr) RegisterHandlers

func (s *Svr) RegisterHandlers(handlers []Handler)

func (*Svr) Run

func (s *Svr) Run(ctx Ctx) error

type TestCase

type TestCase struct {
	Description string
	Input       TestCaseInput
	Error       bool
	Result      interface{}
}

type TestCaseInput

type TestCaseInput struct {
	Ctx      Ctx
	Rpc      interface{}
	Body     string
	Req      proto.Message
	BeforeFn func()
	AfterFn  func()
}

Jump to

Keyboard shortcuts

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