add log
This commit is contained in:
parent
a0826d5361
commit
ebfb2c1ca5
|
@ -3,21 +3,23 @@ package config
|
|||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"log"
|
||||
|
||||
"encoding/json"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
"git.pyer.club/kingecg/gologger"
|
||||
"github.com/fsnotify/fsnotify"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// Config 系统配置结构体
|
||||
type Config struct {
|
||||
Server ServerConfig `yaml:"server" json:"server"`
|
||||
Storage StorageConfig `yaml:"storage" json:"storage"`
|
||||
Server ServerConfig `yaml:"server" json:"server"`
|
||||
Storage StorageConfig `yaml:"storage" json:"storage"`
|
||||
Log gologger.LoggersConfig `yaml:"log" json:"log"`
|
||||
}
|
||||
|
||||
// ServerConfig 服务器配置
|
||||
|
@ -49,6 +51,20 @@ func NewDefaultConfig() *Config {
|
|||
Engine: "memory",
|
||||
DataPath: "/var/lib/goaidb",
|
||||
},
|
||||
Log: gologger.LoggersConfig{
|
||||
Appenders: map[string]gologger.LogAppenderConfig{
|
||||
"console": {
|
||||
Type: "console",
|
||||
Formatter: "text",
|
||||
Options: map[string]interface{}{},
|
||||
},
|
||||
},
|
||||
Categories: map[string]gologger.LogConfig{
|
||||
"default": {
|
||||
Appenders: []string{"console"},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
3
go.mod
3
go.mod
|
@ -1,4 +1,4 @@
|
|||
module github.com/kingecg/goaidb
|
||||
module git.pyer.club/kingecg/goaidb
|
||||
|
||||
go 1.23
|
||||
|
||||
|
@ -7,6 +7,7 @@ go 1.23
|
|||
// require github.com/mongodb/mongo-go-driver/v2 v2.0.0
|
||||
|
||||
require (
|
||||
git.pyer.club/kingecg/gologger v1.0.8 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/fsnotify/fsnotify v1.9.0 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
|
|
4
go.sum
4
go.sum
|
@ -1,3 +1,7 @@
|
|||
git.pyer.club/kingecg/gologger v1.0.7 h1:sMrz+F806Whon6kzxVPYYMqB5frUvvJQEWa2zevRvX8=
|
||||
git.pyer.club/kingecg/gologger v1.0.7/go.mod h1:SNSl2jRHPzIpHSzdKOoVG798rtYMjPDPFyxUrEgivkY=
|
||||
git.pyer.club/kingecg/gologger v1.0.8 h1:DaPDIsn0Jc+hF97+MRuG//W9zuXdPR7VTc+nPkXvym0=
|
||||
git.pyer.club/kingecg/gologger v1.0.8/go.mod h1:SNSl2jRHPzIpHSzdKOoVG798rtYMjPDPFyxUrEgivkY=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
|
||||
|
|
19
main.go
19
main.go
|
@ -9,9 +9,10 @@ import (
|
|||
|
||||
"syscall"
|
||||
|
||||
"github.com/kingecg/goaidb/config"
|
||||
"github.com/kingecg/goaidb/network"
|
||||
"github.com/kingecg/goaidb/storage"
|
||||
"git.pyer.club/kingecg/goaidb/config"
|
||||
"git.pyer.club/kingecg/goaidb/log"
|
||||
"git.pyer.club/kingecg/goaidb/network"
|
||||
"git.pyer.club/kingecg/goaidb/storage"
|
||||
)
|
||||
|
||||
func getExeDir() string {
|
||||
|
@ -36,7 +37,8 @@ func main() {
|
|||
// 解析配置文件
|
||||
cfg, err := config.ParseConfig(configPath)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "配置加载失败: %v\n", err)
|
||||
// fmt.Fprintf(os.Stderr, "配置加载失败: %v\n", err)
|
||||
log.Error("配置加载失败", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
@ -47,6 +49,7 @@ func main() {
|
|||
err = config.WatchConfig(configPath)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "配置监控启动失败: %v\n", err)
|
||||
log.Error("配置监控启动失败", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
@ -56,7 +59,7 @@ func main() {
|
|||
|
||||
go func() {
|
||||
<-sigChan
|
||||
fmt.Println("正在关闭...")
|
||||
log.Info("正在关闭...")
|
||||
config.CloseWatcher()
|
||||
os.Exit(0)
|
||||
}()
|
||||
|
@ -64,7 +67,7 @@ func main() {
|
|||
// 初始化存储引擎(默认使用内存引擎)
|
||||
storageEngine, err := storage.NewMemoryEngine()
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to initialize storage engine: %v\n", err)
|
||||
log.Error("Failed to initialize storage engine: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -74,10 +77,10 @@ func main() {
|
|||
// 启动服务
|
||||
listener, err := net.Listen("tcp", conf.Server.Host+":"+fmt.Sprintf("%d", conf.Server.Port))
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to start server: %v\n", err)
|
||||
log.Error("Failed to start server: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("GoAIDB started on port 27017")
|
||||
log.Info("GoAIDB started on port", conf.Server.Port)
|
||||
server.Serve(listener)
|
||||
}
|
||||
|
|
|
@ -5,9 +5,10 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"github.com/kingecg/goaidb/protocol"
|
||||
"github.com/kingecg/goaidb/query"
|
||||
"github.com/kingecg/goaidb/storage"
|
||||
|
||||
"git.pyer.club/kingecg/goaidb/protocol"
|
||||
"git.pyer.club/kingecg/goaidb/query"
|
||||
"git.pyer.club/kingecg/goaidb/storage"
|
||||
)
|
||||
|
||||
// Server 网络服务器结构体
|
||||
|
@ -67,4 +68,4 @@ func (s *Server) handleConnection(conn net.Conn) {
|
|||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,9 @@ package query
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/kingecg/goaidb/protocol"
|
||||
"github.com/kingecg/goaidb/storage"
|
||||
|
||||
"git.pyer.club/kingecg/goaidb/protocol"
|
||||
"git.pyer.club/kingecg/goaidb/storage"
|
||||
)
|
||||
|
||||
// HandleQuery 处理查询请求
|
||||
|
@ -36,4 +37,4 @@ func handleOPInsert(message *protocol.Message, engine storage.StorageEngine) ([]
|
|||
// 调用存储引擎进行数据插入
|
||||
// 构造响应消息
|
||||
return []byte{0x01, 0x00, 0x00, 0x00}, nil // 返回简单测试响应
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue