| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- // Author: simon (ynwdlxm@163.com)
- // Date: 2025/5/26 11:33
- // Desc:
- //go:build !debug
- package main
- import (
- "fmt"
- "os"
- "github.com/runningwater/go-redis/config"
- "github.com/runningwater/go-redis/lib/logger"
- "github.com/runningwater/go-redis/resp/handler"
- "github.com/runningwater/go-redis/tcp"
- )
- const debug = true
- const configFile string = "redis.conf"
- var defaultProperties = &config.ServerProperties{
- Bind: "0.0.0.0",
- Port: 6379,
- }
- func fileExists(fileName string) bool {
- info, err := os.Stat(fileName)
- return err == nil && !info.IsDir()
- }
- func main() {
- logger.Setup(&logger.Settings{
- Path: "logs",
- Name: "go-redis",
- Ext: "log",
- TimeFormat: "2006-01-02",
- })
- if fileExists(configFile) {
- config.SetupConfig(configFile)
- } else {
- config.Properties = defaultProperties
- }
- addr := fmt.Sprintf("%s:%d", config.Properties.Bind, config.Properties.Port)
- logger.Info("server starting ...")
- err := tcp.ListenAndServeWithSignal(
- &tcp.Config{
- Address: addr,
- },
- // tcp.NewEchoHandler(),
- handler.NewHandler(),
- )
- if err != nil {
- logger.Error(err)
- }
- }
|