-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
82 lines (68 loc) · 1.98 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"errors"
"fmt"
"log"
"os"
bc "github.com/bitCaskKV/bitCask"
"github.com/bitCaskKV/global"
"github.com/bitCaskKV/pkg/logger"
"github.com/bitCaskKV/pkg/setting"
"github.com/bitCaskKV/server/routers"
"gopkg.in/natefinch/lumberjack.v2"
)
// A simple Router
func init() {
err := setupSetting()
if err != nil {
log.Fatalf("Setting Config Load Fail Error:%s", err.Error())
}
err = setupLogger()
if err != nil {
log.Fatalf("Global Logger Load Fail Error:%s", err.Error())
}
// if global.ServerSetting.RunMode != "debug" {
err = setupBitCaskEngine()
if err != nil {
log.Fatalf("Default Engine Initialize Fail Error:%s", err.Error())
}
// }
}
// @title 基于BitCask的K-V储存系统
// @version 1.0
// @description 基于BitCask K-V储存系统服务端
// @termsofService https://github.com/Zrealshadow/bitCask-kv
func main() {
r := routers.NewRouter()
r.Run(global.ServerSetting.Addr + ":" + global.ServerSetting.HttpPort)
}
func setupSetting() error {
setting, _ := setting.NewSetting()
err := setting.ReadSection("Server", &global.ServerSetting)
if err != nil {
return errors.New(fmt.Sprintf("Server Config Read Error: %s", err.Error()))
}
err = setting.ReadSection("Logger", &global.LoggerSetting)
if err != nil {
return errors.New(fmt.Sprintf("Logger Config Read Error: %s", err.Error()))
}
err = setting.ReadSection("DB", &global.BitCaskSetting)
if err != nil {
return errors.New(fmt.Sprintf("BitCask Engine Config Read Error: %s", err.Error()))
}
return nil
}
func setupLogger() error {
global.Logger = logger.NewLogger(
&lumberjack.Logger{
Filename: global.LoggerSetting.LogSavePath + string(os.PathSeparator) + global.LoggerSetting.LogFileExt,
MaxSize: global.LoggerSetting.MaxPageSize,
MaxAge: global.LoggerSetting.DefaultPageSize,
LocalTime: true,
}, "", log.LstdFlags)
return nil
}
func setupBitCaskEngine() error {
global.DefaultBitCaskEngine, _ = bc.NewBitCaskEngine(global.BitCaskSetting.MountDir)
return nil
}