Fetch the repository succeeded.
package server
import (
"encoding/json"
"gitee.com/zuokuan/zrpc"
"gitee.com/zuokuan/zrpc/po"
"gitee.com/zuokuan/zrpc/util"
"log"
)
func NewSimplePlugin(n *pluginFunctions) *zrpc.Plugin {
return &zrpc.Plugin{PluginFunctions: n.m}
}
func NewApiPlugin(AppName, AppDesc string, Port int, fs ...*zrpc.PluginFunction) *zrpc.Plugin {
var functions []po.Function
var functionMap = make(map[string]zrpc.PluginFunctionInterface)
for _, f := range fs {
if f.Name() == "" {
log.Fatal("存在未定义函数名称的函数")
}
functions = append(functions, f.Info())
functionMap[f.Name()] = f
}
functions = append(functions, logoutFunction.Info())
functions = append(functions, aliveFunction.Info())
functionMap[logoutFunction.Name()] = logoutFunction
functionMap[aliveFunction.Name()] = aliveFunction
marshal, err := json.Marshal(functions)
if err != nil {
log.Fatal(err)
}
var plugin = zrpc.Plugin{PluginFunctions: functionMap, AppInfo: po.AppInfo{AppName: AppName, AppDesc: AppDesc, Port: Port, FunctionList: string(marshal)}}
return &plugin
}
type pluginFunctions struct {
m map[string]zrpc.PluginFunctionInterface
}
func FunctionBuilder() *pluginFunctions {
return &pluginFunctions{m: make(map[string]zrpc.PluginFunctionInterface)}
}
func (f *pluginFunctions) Add(funcName string, function zrpc.PluginFunctionInterface) *pluginFunctions {
f.m[funcName] = function
return f
}
func NewFunction() *zrpc.PluginFunction {
return &zrpc.PluginFunction{}
}
func (f *pluginFunctions) AddForAPI(function zrpc.PluginFunctionInterface) *pluginFunctions {
f.m[function.Name()] = function
return f
}
func NewFunctionForApi(FunctionName, FunctionNameDesc, FunctionDesc string) *zrpc.PluginFunction {
return zrpc.NewPluginFunction(FunctionName, FunctionNameDesc, FunctionDesc)
}
var logoutFunction = NewFunctionForApi("Logout", "登出服务", "公共服务,实现服务退出").
SetArgs().
Action(func(request zrpc.CallRequest, result *zrpc.CallResult) error {
go util.Logout()
return nil
})
var aliveFunction = NewFunctionForApi("Alive", "存活验证", "公共服务,实现服务存活验证").
SetArgs().
Action(func(request zrpc.CallRequest, result *zrpc.CallResult) error {
result.SuccessMsg("Alive!")
return nil
})
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。