李寻欢 4ca9c5e2d7
Some checks failed
BuildImage / build-image (push) Has been cancelled
:feature: 添加容器内存限制配置,默认值设置为512MB
2025-04-22 21:21:06 +08:00

41 lines
1.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package config
import (
"fmt"
)
// RedisConfig 是Redis相关配置
type RedisConfig struct {
Host string `mapstructure:"host"`
Password string `mapstructure:"password"`
DB int `mapstructure:"db"`
}
// DockerConfig Docker配置
type DockerConfig struct {
Host string `mapstructure:"host"` // Docker daemon 主机地址
APIVersion string `mapstructure:"apiVersion"` // Docker API版本
ImageName string `mapstructure:"imageName"` // 微信机器人Docker镜像名称
Network string `mapstructure:"network"` // 容器网络
Memory int64 `mapstructure:"memory"` // 内存限制
Redis RedisConfig `mapstructure:"redis"` // Redis配置
}
// Validate 验证Docker配置
func (c *DockerConfig) Validate() error {
if c.ImageName == "" {
return fmt.Errorf("docker image name cannot be empty")
}
// 如果没有指定Docker主机则使用默认值
if c.Host == "" {
c.Host = "unix:///var/run/docker.sock"
}
if c.Network == "" {
c.Network = "bridge"
}
return nil
}