3 Star 2 Fork 0

info-superbahn-ict / superbahn

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
docker_client.go 1.93 KB
一键复制 编辑 原始数据 按行查看 历史
tangshibo 提交于 2021-12-29 12:22 . update
package docker_cli
import (
"context"
"crypto/rand"
"fmt"
"gitee.com/info-superbahn-ict/superbahn/pkg/supbmanager/v3_test/supb-modules/supbres/compose"
"gitee.com/info-superbahn-ict/superbahn/v3_test/supbenv/log"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"strings"
)
type Client struct {
ctx context.Context
prefix string
logger log.Logger
}
func NewDockerClient(ctx context.Context, prefix string) *Client {
return &Client{
ctx: ctx,
prefix: prefix,
logger: log.NewLogger(prefix),
}
}
func (r *Client) InitFlags(flags *pflag.FlagSet) {
}
func (r *Client) ViperConfig(viper *viper.Viper) {
}
func (r *Client) InitViper(viper *viper.Viper) {
}
func (r *Client) OptionConfig(opts ...option) {
for _, apply := range opts {
apply(r)
}
}
func (r *Client) Initialize(opts ...option) {
for _, apply := range opts {
apply(r)
}
r.logger.Infof("%v initialized", r.prefix)
}
func (r *Client) Close() error {
r.logger.Infof("%v closed", r.prefix)
return nil
}
func (r *Client) Run(cmp *compose.Containers) (*compose.RunningBaseInfo, error) {
randBytes := make([]byte, 8)
if _, err := rand.Read(randBytes); err != nil {
return nil, fmt.Errorf("generate name %v", err)
}
name := strings.Join([]string{"CONTAIN", fmt.Sprintf("%x", randBytes)}, "_")
randBytes = make([]byte, 16)
if _, err := rand.Read(randBytes); err != nil {
return nil, fmt.Errorf("generate name %v", err)
}
CID := fmt.Sprintf("%x", randBytes)
randBytes = make([]byte, 16)
if _, err := rand.Read(randBytes); err != nil {
return nil, fmt.Errorf("generate name %v", err)
}
Guid := fmt.Sprintf("%x", randBytes)
return &compose.RunningBaseInfo{
ContainerName: name,
CID: CID,
Guid: Guid,
}, nil
}
func (r *Client) Remove(compose *compose.Containers) error {
return nil
}
func (r *Client) Stop(compose *compose.Containers) error {
return nil
}
func (r *Client) Restart(compose *compose.Containers) error {
return nil
}
Go
1
https://gitee.com/info-superbahn-ict/superbahn.git
git@gitee.com:info-superbahn-ict/superbahn.git
info-superbahn-ict
superbahn
superbahn
5fda629dab96

搜索帮助