This commit is contained in:
2025-07-18 12:14:29 +08:00
parent 519dfaeb13
commit 18a07dd5b3
9 changed files with 43 additions and 15 deletions

View File

@@ -18,4 +18,11 @@ CONFIG_FILE_PATH = $(PWD)/ignore/secret.yaml
# 如果运行,使用的成员信息文件在哪里? # 如果运行,使用的成员信息文件在哪里?
CSV_PATH = $(PWD)/ignore/aa.csv CSV_PATH = $(PWD)/ignore/aa.csv
# 运行端口
LISTEN_PORT = 25005
# 模板文件的目录
TEMPLATE_DIR = $(PWD)/src/templates
# 前端文件的目录
FRONTEND_PATH = $(PWD)/src/FrontEnd
include build/Makefile include build/Makefile

0
aa.csv
View File

View File

@@ -15,5 +15,5 @@ build: BackEnd
run: run:
$(TARGET_PATH)/scheduler --config $(CONFIG_FILE_PATH) --csv-path $(CSV_PATH) TEMPLATE=$(TEMPLATE_DIR) FRONTEND=$(FRONTEND_PATH) CSV_PATH=$(CSV_PATH) $(TARGET_PATH)/scheduler --config $(CONFIG_FILE_PATH)

18
config.yaml Normal file
View File

@@ -0,0 +1,18 @@
# 其中有的配置可以通过环境变量覆盖,前端,模板的路径通过环境变量设置
# 这是一个示例配置文件。
app:
Name: "scheduler for ZSC Network Support staff"
ListenPort: 25005
File: "member.csv" #成员信息文件的路径,看文档
DB:
Type: "SQLite"
Path: "./scheduler.db"
Port: ""
User: ""
Password: ""
Name: ""
business:
Session: "2024-2025" #学年
Semester: 1 #学期1 或 2
StartTime: "2025-3-10" #开始值班的日期,日期必须是星期一
Week: 15 #准备值班多少周

2
member.csv Normal file
View File

@@ -0,0 +1,2 @@
工号,姓名,性别,有空,有空(备用),权限
1001,示例,1,0,0,1
1 工号 姓名 性别 有空 有空(备用) 权限
2 1001 示例 1 0 0 1

View File

@@ -3,6 +3,7 @@ package config
import ( import (
"fmt" "fmt"
"os" "os"
"strconv"
"github.com/golang-module/carbon/v2" "github.com/golang-module/carbon/v2"
"github.com/spf13/pflag" "github.com/spf13/pflag"
@@ -34,21 +35,25 @@ func readconfig() {
if err := viper.Unmarshal(&Default); err != nil { if err := viper.Unmarshal(&Default); err != nil {
panic(fmt.Errorf("映射配置到结构体失败: %s", err)) panic(fmt.Errorf("映射配置到结构体失败: %s", err))
} }
FrontEnd = os.Getenv("FRONTEND")
} }
func parseArgs() { func parseArgs() {
pflag.String("config", "./config.yaml", "the path to config file.") pflag.String("config", "./config.yaml", "the path to config file.")
pflag.Bool("init-db", false, "whether to initialize the database on starting,useful when migrating to a new one.") pflag.Bool("init-db", false, "whether to initialize the database on starting,useful when migrating to a new one.")
pflag.String("csv-path", "./member.csv", "the CSV file containing member information")
viper.BindPFlags(pflag.CommandLine) viper.BindPFlags(pflag.CommandLine)
pflag.Parse() pflag.Parse()
pathToConfigure = viper.GetString("config") pathToConfigure = viper.GetString("config")
InitDB = viper.GetBool("init-db") InitDB = viper.GetBool("init-db")
CSVPath = viper.GetString("csv-path")
} }
func overrides() { func overrides() {
if CSVPath != "" { if CSVPath := os.Getenv("CSV_PATH"); CSVPath != "" {
Default.App.File = CSVPath Default.App.File = CSVPath
} }
if ListenPort, err := strconv.Atoi(os.Getenv("LISTEN_PORT")); ListenPort != 0 && err != nil {
Default.App.ListenPort = ListenPort
}
} }

View File

@@ -26,4 +26,4 @@ type Config struct {
var pathToConfigure string //配置文件的路径 var pathToConfigure string //配置文件的路径
var Default Config //系统的默认配置 var Default Config //系统的默认配置
var InitDB bool var InitDB bool
var CSVPath string var FrontEnd string

View File

@@ -27,8 +27,10 @@ func main() {
route.Route(app) //注册路由表 route.Route(app) //注册路由表
route.Middleware(app) //注册中间件 route.Middleware(app) //注册中间件
// 暂时在初始化时不注册模板,因为用不上 renderer := tl.Tlw{
//registerTemplate(app) //注册模板 Tl: template.Must(template.ParseGlob(os.Getenv("TEMPLATE") + "/*.html")),
}
app.Renderer = renderer //注册模板
listenAddress := fmt.Sprintf(":%d", config.Default.App.ListenPort) listenAddress := fmt.Sprintf(":%d", config.Default.App.ListenPort)
@@ -48,10 +50,3 @@ func csv() {
panic(err) panic(err)
} }
} }
func registerTemplate(app *echo.Echo) {
renderer := tl.Tlw{
Tl: template.Must(template.ParseGlob("templates/*.html")),
}
app.Renderer = renderer
}

View File

@@ -3,13 +3,14 @@ package route
import ( import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware" "github.com/labstack/echo/v4/middleware"
"zsxyww.com/scheduler/config"
"zsxyww.com/scheduler/handler" "zsxyww.com/scheduler/handler"
) )
func Route(app *echo.Echo) { func Route(app *echo.Echo) {
// here is the route for our site // here is the route for our site
staticFiles := app.Group("/*") staticFiles := app.Group("/*")
staticFiles.Use(middleware.Static("./FrontEnd")) staticFiles.Use(middleware.Static(config.FrontEnd))
api := app.Group("/api/") api := app.Group("/api/")
api.GET("getAssignment", handler.GetAssignment) api.GET("getAssignment", handler.GetAssignment)