mirror of
https://gitee.com/WuKongDev/WuKongIM.git
synced 2025-12-06 14:59:08 +08:00
feat: update
This commit is contained in:
@@ -8,6 +8,8 @@ external:
|
||||
ip: "" # 如果节点部署在内网,需要配置外网ip,否则外网的客户端无法连接到此节点
|
||||
# tcpAddr: "" # 默认自动获取, 节点的TCP地址 对外公开,APP端长连接通讯 格式: ip:port
|
||||
# wssAddr: "" # 默认自动获取, 节点的wsAdd地址 对外公开 WEB端长连接通讯 格式: ip:port
|
||||
# monitorAddr: "" # 默认自动获取, 节点的monitor地址 对外公开 监控服务 格式: ip:port
|
||||
# ginMode: "release" # gin框架的模式 debug 调试 release 正式 test 测试
|
||||
# logger:
|
||||
# level: 0 # 日志级别 0:未配置,将根据mode属性判断 1:debug 2:info 3:warn 4:error
|
||||
# dir: "./logs" # 日志目录
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/WuKongIM/WuKongIM/pkg/wkproto"
|
||||
"github.com/WuKongIM/WuKongIM/pkg/wkutil"
|
||||
"github.com/WuKongIM/WuKongIM/version"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/spf13/cast"
|
||||
"github.com/spf13/viper"
|
||||
"go.uber.org/zap/zapcore"
|
||||
@@ -38,6 +39,7 @@ type Options struct {
|
||||
Addr string // tcp监听地址 例如:tcp://0.0.0.0:5100
|
||||
RootDir string // 根目录
|
||||
DataDir string // 数据目录
|
||||
GinMode string // gin框架的模式
|
||||
WSS struct {
|
||||
On bool // 是否开启wss
|
||||
Addr string // websocket 监听地址 例如:0.0.0.0:5200
|
||||
@@ -52,9 +54,10 @@ type Options struct {
|
||||
Addr string // 监控地址 默认为 0.0.0.0:5300
|
||||
}
|
||||
External struct {
|
||||
IP string // 外网IP 如果没配置将通过ifconfig.io获取
|
||||
TCPAddr string // 节点的TCP地址 对外公开,APP端长连接通讯 格式: ip:port
|
||||
WSSAddr string // 节点的wssAdd地址 对外公开 WEB端长连接通讯 格式: ip:port
|
||||
IP string // 外网IP 如果没配置将通过ifconfig.io获取
|
||||
TCPAddr string // 节点的TCP地址 对外公开,APP端长连接通讯 格式: ip:port
|
||||
WSSAddr string // 节点的wssAdd地址 对外公开 WEB端长连接通讯 格式: ip:port
|
||||
MonitorAddr string // 对外访问的监控地址
|
||||
}
|
||||
Channel struct { // 频道配置
|
||||
CacheCount int // 频道缓存数量
|
||||
@@ -128,6 +131,7 @@ func NewOptions() *Options {
|
||||
Version: version.Version,
|
||||
TimingWheelTick: time.Millisecond * 10,
|
||||
TimingWheelSize: 100,
|
||||
GinMode: gin.ReleaseMode,
|
||||
RootDir: path.Join(homeDir, "wukongim"),
|
||||
Logger: struct {
|
||||
Dir string
|
||||
@@ -222,6 +226,7 @@ func (o *Options) ConfigureWithViper(vp *viper.Viper) {
|
||||
o.RootDir = o.getString("rootDir", o.RootDir)
|
||||
|
||||
o.Mode = Mode(o.getString("mode", string(ReleaseMode)))
|
||||
o.GinMode = o.getString("ginMode", o.GinMode)
|
||||
|
||||
o.HTTPAddr = o.getString("httpAddr", o.HTTPAddr)
|
||||
o.Addr = o.getString("addr", o.Addr)
|
||||
@@ -229,6 +234,7 @@ func (o *Options) ConfigureWithViper(vp *viper.Viper) {
|
||||
o.External.IP = o.getString("external.ip", o.External.IP)
|
||||
o.External.TCPAddr = o.getString("external.tcpAddr", o.External.TCPAddr)
|
||||
o.External.WSSAddr = o.getString("external.wssAddr", o.External.WSSAddr)
|
||||
o.External.MonitorAddr = o.getString("external.monitorAddr", o.External.MonitorAddr)
|
||||
|
||||
o.Monitor.On = o.getBool("monitor.on", o.Monitor.On)
|
||||
o.Monitor.Addr = o.getString("monitor.addr", o.Monitor.Addr)
|
||||
@@ -290,14 +296,13 @@ func (o *Options) ConfigureWithViper(vp *viper.Viper) {
|
||||
o.configureDataDir() // 数据目录
|
||||
o.configureLog(vp) // 日志配置
|
||||
|
||||
ip := getIntranetIP()
|
||||
if strings.TrimSpace(o.External.TCPAddr) == "" {
|
||||
addrPairs := strings.Split(o.Addr, ":")
|
||||
portInt64, _ := strconv.ParseInt(addrPairs[len(addrPairs)-1], 10, 64)
|
||||
|
||||
ip := ""
|
||||
var err error
|
||||
|
||||
ip = getIntranetIP()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -307,10 +312,15 @@ func (o *Options) ConfigureWithViper(vp *viper.Viper) {
|
||||
if strings.TrimSpace(o.External.WSSAddr) == "" {
|
||||
addrPairs := strings.Split(o.WSS.Addr, ":")
|
||||
portInt64, _ := strconv.ParseInt(addrPairs[len(addrPairs)-1], 10, 64)
|
||||
ip := getIntranetIP()
|
||||
o.External.WSSAddr = fmt.Sprintf("%s:%d", ip, portInt64)
|
||||
}
|
||||
|
||||
if strings.TrimSpace(o.External.MonitorAddr) == "" {
|
||||
addrPairs := strings.Split(o.Monitor.Addr, ":")
|
||||
portInt64, _ := strconv.ParseInt(addrPairs[len(addrPairs)-1], 10, 64)
|
||||
o.External.MonitorAddr = fmt.Sprintf("%s:%d", ip, portInt64)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (o *Options) configureDataDir() {
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/WuKongIM/WuKongIM/pkg/wkstore"
|
||||
"github.com/WuKongIM/WuKongIM/pkg/wkutil"
|
||||
"github.com/WuKongIM/WuKongIM/version"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/judwhite/go-svc"
|
||||
"github.com/panjf2000/ants/v2"
|
||||
)
|
||||
@@ -68,6 +69,8 @@ func New(opts *Options) *Server {
|
||||
start: now,
|
||||
}
|
||||
|
||||
gin.SetMode(opts.GinMode)
|
||||
|
||||
storeCfg := wkstore.NewStoreConfig()
|
||||
storeCfg.DataDir = s.opts.DataDir
|
||||
storeCfg.DecodeMessageFnc = func(msg []byte) (wkstore.Message, error) {
|
||||
|
||||
6
main.go
6
main.go
@@ -1,11 +1,17 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/WuKongIM/WuKongIM/cmd"
|
||||
)
|
||||
|
||||
var Version string
|
||||
|
||||
func main() {
|
||||
|
||||
fmt.Println("WuKongIM version:", Version)
|
||||
|
||||
// logFile, err := os.OpenFile("./fatal.log", os.O_CREATE|os.O_APPEND|os.O_RDWR, 0660)
|
||||
// if err != nil {
|
||||
// log.Println("服务启动出错", "打开异常日志文件失败", err)
|
||||
|
||||
@@ -62,7 +62,7 @@ func NewFileStore(cfg *StoreConfig) *FileStore {
|
||||
func (f *FileStore) Open() error {
|
||||
f.lock.StartCleanLoop()
|
||||
var err error
|
||||
f.db, err = bolt.Open(filepath.Join(f.cfg.DataDir, "wukongim.db"), 0600, &bolt.Options{Timeout: 10 * time.Second})
|
||||
f.db, err = bolt.Open(filepath.Join(f.cfg.DataDir, "wukongim.db"), 0755, &bolt.Options{Timeout: 10 * time.Second})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ binary: wukongim-{{ .Os }}-{{ .Arch }}
|
||||
|
||||
# (Optional) ldflags generated dynamically in the workflow, and set as the `evaluated-envs` input variables in the workflow.
|
||||
ldflags:
|
||||
- "-X version.Version={{ .Env.VERSION }}"
|
||||
- "-X version.Commit={{ .Env.COMMIT }}"
|
||||
- "-X version.CommitDate={{ .Env.COMMIT_DATE }}"
|
||||
- "-X version.TreeState={{ .Env.TREE_STATE }}"
|
||||
- "-X github.com/$GITHUB_REPOSITORY/version.Version={{ .Env.VERSION }}"
|
||||
- "-X github.com/$GITHUB_REPOSITORY/version.Commit={{ .Env.COMMIT }}"
|
||||
- "-X github.com/$GITHUB_REPOSITORY/version.CommitDate={{ .Env.COMMIT_DATE }}"
|
||||
- "-X github.com/$GITHUB_REPOSITORY/version.TreeState={{ .Env.TREE_STATE }}"
|
||||
@@ -30,7 +30,7 @@ binary: wukongim-{{ .Os }}-{{ .Arch }}
|
||||
|
||||
# (Optional) ldflags generated dynamically in the workflow, and set as the `evaluated-envs` input variables in the workflow.
|
||||
ldflags:
|
||||
- "-X version.Version={{ .Env.VERSION }}"
|
||||
- "-X version.Commit={{ .Env.COMMIT }}"
|
||||
- "-X version.CommitDate={{ .Env.COMMIT_DATE }}"
|
||||
- "-X version.TreeState={{ .Env.TREE_STATE }}"
|
||||
- "-X github.com/$GITHUB_REPOSITORY/version.Version={{ .Env.VERSION }}"
|
||||
- "-X github.com/$GITHUB_REPOSITORY/version.Commit={{ .Env.COMMIT }}"
|
||||
- "-X github.com/$GITHUB_REPOSITORY/version.CommitDate={{ .Env.COMMIT_DATE }}"
|
||||
- "-X github.com/$GITHUB_REPOSITORY/version.TreeState={{ .Env.TREE_STATE }}"
|
||||
@@ -30,7 +30,7 @@ binary: wukongim-{{ .Os }}-{{ .Arch }}
|
||||
|
||||
# (Optional) ldflags generated dynamically in the workflow, and set as the `evaluated-envs` input variables in the workflow.
|
||||
ldflags:
|
||||
- "-X version.Version={{ .Env.VERSION }}"
|
||||
- "-X version.Commit={{ .Env.COMMIT }}"
|
||||
- "-X version.CommitDate={{ .Env.COMMIT_DATE }}"
|
||||
- "-X version.TreeState={{ .Env.TREE_STATE }}"
|
||||
- "-X github.com/$GITHUB_REPOSITORY/version.Version={{ .Env.VERSION }}"
|
||||
- "-X github.com/$GITHUB_REPOSITORY/version.Commit={{ .Env.COMMIT }}"
|
||||
- "-X github.com/$GITHUB_REPOSITORY/version.CommitDate={{ .Env.COMMIT_DATE }}"
|
||||
- "-X github.com/$GITHUB_REPOSITORY/version.TreeState={{ .Env.TREE_STATE }}"
|
||||
@@ -30,7 +30,7 @@ binary: wukongim-{{ .Os }}-{{ .Arch }}
|
||||
|
||||
# (Optional) ldflags generated dynamically in the workflow, and set as the `evaluated-envs` input variables in the workflow.
|
||||
ldflags:
|
||||
- "-X version.Version={{ .Env.VERSION }}"
|
||||
- "-X version.Commit={{ .Env.COMMIT }}"
|
||||
- "-X version.CommitDate={{ .Env.COMMIT_DATE }}"
|
||||
- "-X version.TreeState={{ .Env.TREE_STATE }}"
|
||||
- "-X github.com/$GITHUB_REPOSITORY/version.Version={{ .Env.VERSION }}"
|
||||
- "-X github.com/$GITHUB_REPOSITORY/version.Commit={{ .Env.COMMIT }}"
|
||||
- "-X github.com/$GITHUB_REPOSITORY/version.CommitDate={{ .Env.COMMIT_DATE }}"
|
||||
- "-X github.com/$GITHUB_REPOSITORY/version.TreeState={{ .Env.TREE_STATE }}"
|
||||
Reference in New Issue
Block a user