beancount-gs/server.go

42 lines
778 B
Go
Raw Normal View History

2021-09-24 08:11:41 +00:00
package main
import (
2021-11-17 09:59:06 +00:00
"github.com/beancount-gs/script"
2021-11-04 09:58:57 +00:00
"github.com/gin-gonic/gin"
2021-11-17 09:59:06 +00:00
"net/http"
2021-09-24 08:11:41 +00:00
)
2021-11-17 09:59:06 +00:00
var GlobalConfig Config
2021-11-17 06:16:22 +00:00
2021-11-17 09:59:06 +00:00
func InitLedgerFiles() {
// 账本目录不存在,则创建
if !script.FileIfExist(GlobalConfig.DataPath) {
script.MkDir(GlobalConfig.DataPath)
script.LogInfo("Success mkdir " + GlobalConfig.DataPath)
}
2021-11-17 06:16:22 +00:00
}
func LoadLedgerCache() {
}
func RegisterRoute(route *gin.Engine) {
route.StaticFS("/", http.Dir("./public"))
}
2021-09-24 08:11:41 +00:00
func main() {
2021-11-17 06:16:22 +00:00
// 默认端口号
var port = ":3001"
2021-11-17 09:59:06 +00:00
// 读取配置文件
GlobalConfig = LoadConfig(GlobalConfig)
2021-11-17 06:16:22 +00:00
// 初始化账本文件结构
InitLedgerFiles()
// 加载缓存
LoadLedgerCache()
2021-11-04 09:58:57 +00:00
route := gin.Default()
2021-11-17 06:16:22 +00:00
// 注册路由
RegisterRoute(route)
2021-11-17 09:59:06 +00:00
// 启动服务
2021-11-17 06:16:22 +00:00
_ = http.ListenAndServe(port, nil)
2021-09-24 08:11:41 +00:00
}