当前仓库属于暂停状态,部分功能使用受限,详情请查阅 仓库状态说明
2 Star 0 Fork 1

JUMEI_ARCH/go-plugins
暂停

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
whitelist.go 1.10 KB
一键复制 编辑 原始数据 按行查看 历史
Asim 提交于 2016-06-06 17:11 . Env var same as flag
// Package whitelist is a micro plugin for whitelisting service requests
package whitelist
import (
"net/http"
"strings"
"github.com/micro/cli"
"github.com/micro/go-micro/client"
"github.com/micro/micro/plugin"
)
type whitelist struct {
services map[string]bool
}
func (w *whitelist) Flags() []cli.Flag {
return []cli.Flag{
cli.StringFlag{
Name: "rpc_whitelist",
Usage: "Comma separated whitelist of allowed services for RPC calls",
EnvVar: "RPC_WHITELIST",
},
}
}
func (w *whitelist) Commands() []cli.Command {
return nil
}
func (w *whitelist) Handler() plugin.Handler {
return func(h http.Handler) http.Handler {
return h
}
}
func (w *whitelist) Init(ctx *cli.Context) error {
if whitelist := ctx.String("rpc_whitelist"); len(whitelist) > 0 {
client.DefaultClient = newClient(strings.Split(whitelist, ",")...)
}
return nil
}
func (w *whitelist) String() string {
return "whitelist"
}
func NewRPCWhitelist(services ...string) plugin.Plugin {
list := make(map[string]bool)
for _, service := range services {
list[service] = true
}
return &whitelist{
services: list,
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/JMArch/go-plugins.git
git@gitee.com:JMArch/go-plugins.git
JMArch
go-plugins
go-plugins
v0.6.0

搜索帮助

0d507c66 1850385 C8b1a773 1850385