style: using is struct to handle all judgements global envs

This commit is contained in:
2026-04-02 21:38:50 +08:00
parent aa22b04a1f
commit 78bd1cb3cc
5 changed files with 48 additions and 27 deletions
+21 -13
View File
@@ -22,23 +22,31 @@ type SoftwareInfo struct {
BuildType string
}
var softwareInfo SoftwareInfo
var softwareInfo SoftwareInfo = SoftwareInfo{
Name: "Super-frpc",
Version: "0.0.1",
Developer: "Madobi Nanami",
BuildVer: 1,
BuildType: "debug",
}
type StatusInfo struct {
Status string
}
var isDebug bool
var isOnline bool
type Is struct {
debug bool
online bool
watchdogConnected bool
}
var is Is = Is {
debug: false,
online: false,
watchdogConnected: false,
}
func main() {
softwareInfo = SoftwareInfo{
Name: "Super-frpc",
Version: "0.0.1",
Developer: "Madobi Nanami",
BuildVer: 1,
BuildType: "debug",
}
postLog.Info(fmt.Sprintf("%s %s (Build %d.%s) by %s", softwareInfo.Name, softwareInfo.Version, softwareInfo.BuildVer, softwareInfo.BuildType, softwareInfo.Developer))
configPath := flag.String("config", "./config.json", "path to config file")
dbPath_data := flag.String("db", "./database.db", "path to database file")
@@ -63,7 +71,7 @@ func main() {
}
postLog.SetDebugMode(config.Debug)
isDebug = config.Debug
is.debug = config.Debug
if err := postLog.InitLogsDatabase(*dbPath_log); err != nil {
postLog.Fatal(fmt.Sprintf("Failed to initialize logs database: %v", err))
@@ -112,7 +120,7 @@ func main() {
go func() {
postLog.Info(fmt.Sprintf("Server starting on %s", addr))
isOnline = true
is.online = true
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
postLog.Fatal(fmt.Sprintf("Failed to start server: %v", err))
}
@@ -152,7 +160,7 @@ func GetStatusHandler(w http.ResponseWriter, r *http.Request) {
statusInfo := StatusInfo{
Status: "Online",
}
if !isOnline {
if !is.online {
statusInfo.Status = "Offline"
}
SendSuccessResponse(w, "getStatus", statusInfo)