1 Star 0 Fork 2

安易科技(北京)有限公司/chameleon

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
option.go 1.78 KB
一键复制 编辑 原始数据 按行查看 历史
Derek Ray 提交于 2025-03-20 16:22 +08:00 . feat(nsenter): optimize nsenter mechanism
package nsenter
import "io"
type nsOptions struct {
types []NsType
pid int
procfs string
envs []string
output io.Writer
uid int
gid int
}
type Option interface {
apply(*nsOptions)
}
type nsTypesOption []NsType
func (opt nsTypesOption) apply(options *nsOptions) {
options.types = opt
}
// Types specify namespace types while creating Namespace instance, supports NET,
// UTS, IPC, USER, and PID.
func Types(types ...NsType) Option {
return nsTypesOption(types)
}
type pidOption int
func (opt pidOption) apply(options *nsOptions) {
options.pid = int(opt)
}
// Pid specify which process attached to for namespaces
func Pid(pid int) Option {
return pidOption(pid)
}
type procfsOption string
func (opt procfsOption) apply(options *nsOptions) {
if string(opt) != "" {
options.procfs = string(opt)
}
}
// Procfs specify host procfs, which is useful for using package in container that
// has bind host /proc into container or starts with host pid namespace
func Procfs(procfs string) Option {
return procfsOption(procfs)
}
type outputOption struct {
output io.Writer
}
func (opt outputOption) apply(options *nsOptions) {
options.output = opt.output
}
// Output specify output writer for execution results, only works for Command
func Output(output io.Writer) Option {
return outputOption{output}
}
type envsOption struct {
envs []string
}
func (opt *envsOption) apply(options *nsOptions) {
options.envs = opt.envs
}
func Envs(envs ...string) Option {
return &envsOption{envs}
}
type uidOption int
func (opt uidOption) apply(options *nsOptions) {
options.uid = int(opt)
}
func UID(uid int) Option {
return uidOption(uid)
}
type gidOption int
func (opt gidOption) apply(options *nsOptions) {
options.gid = int(opt)
}
func GID(gid int) Option {
return gidOption(gid)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/anesec/chameleon.git
git@gitee.com:anesec/chameleon.git
anesec
chameleon
chameleon
205da4a0ed50

搜索帮助