main.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Author: simon (ynwdlxm@163.com)
  2. // Date: 2025/5/26 11:33
  3. // Desc:
  4. //go:build !debug
  5. package main
  6. import (
  7. "fmt"
  8. "os"
  9. "github.com/runningwater/go-redis/config"
  10. "github.com/runningwater/go-redis/lib/logger"
  11. "github.com/runningwater/go-redis/resp/handler"
  12. "github.com/runningwater/go-redis/tcp"
  13. )
  14. const debug = true
  15. const configFile string = "redis.conf"
  16. var defaultProperties = &config.ServerProperties{
  17. Bind: "0.0.0.0",
  18. Port: 6379,
  19. }
  20. func fileExists(fileName string) bool {
  21. info, err := os.Stat(fileName)
  22. return err == nil && !info.IsDir()
  23. }
  24. func main() {
  25. logger.Setup(&logger.Settings{
  26. Path: "logs",
  27. Name: "go-redis",
  28. Ext: "log",
  29. TimeFormat: "2006-01-02",
  30. })
  31. if fileExists(configFile) {
  32. config.SetupConfig(configFile)
  33. } else {
  34. config.Properties = defaultProperties
  35. }
  36. addr := fmt.Sprintf("%s:%d", config.Properties.Bind, config.Properties.Port)
  37. logger.Info("server starting ...")
  38. err := tcp.ListenAndServeWithSignal(
  39. &tcp.Config{
  40. Address: addr,
  41. },
  42. // tcp.NewEchoHandler(),
  43. handler.NewHandler(),
  44. )
  45. if err != nil {
  46. logger.Error(err)
  47. }
  48. }