Files
honoka-chan/config/config.go
T
YumeMichi 0aacf8a4e9 Improve live and random live handling
- Add random live handlers, schemas and persistence for lot/play/continue/gameover/reward flow
- Update live status and schedule generation, including special rotation handling and CN timezone alignment
- Add config support for unlocking all daily special rotation songs and document the option
- Refresh live play, reward, precise score and session logic plus bundled main.db updates

Signed-off-by: Sean Du <do4suki@gmail.com>
2026-06-06 20:59:45 +08:00

69 lines
1.4 KiB
Go

package config
import (
"encoding/json"
"honoka-chan/pkg/utils"
"os"
"strconv"
"time"
)
var (
Conf = &AppConfigs{}
PackageVersion = "97.4.6"
PrivateKeyPath = "assets/certs/privatekey.pem"
PublicKeyPath = "assets/certs/publickey.pem"
)
type AppConfigs struct {
AppName string `json:"app_name"`
Settings Settings `json:"settings"`
}
type Settings struct {
ListenPort string `json:"listen_port"`
CdnServer string `json:"cdn_server"`
UnlockAllSpecialRotation bool `json:"unlock_all_special_rotation"`
}
func InitConfig() {
Conf = Load("./config.json")
}
func DefaultConfigs() *AppConfigs {
return &AppConfigs{
AppName: "honoka-chan",
Settings: Settings{
ListenPort: "8080",
CdnServer: "http://127.0.0.1:8080/static",
UnlockAllSpecialRotation: false,
},
}
}
func Load(p string) *AppConfigs {
if !utils.PathExists(p) {
_ = DefaultConfigs().Save(p)
}
c := AppConfigs{}
err := json.Unmarshal([]byte(utils.ReadAllText(p)), &c)
if err != nil {
_ = os.Rename(p, p+".backup"+strconv.FormatInt(time.Now().Unix(), 10))
_ = DefaultConfigs().Save(p)
}
c = AppConfigs{}
_ = json.Unmarshal([]byte(utils.ReadAllText(p)), &c)
return &c
}
func (c *AppConfigs) Save(p string) error {
data, err := json.MarshalIndent(c, "", " ")
if err != nil {
return err
}
utils.WriteAllText(p, string(data)+"\n")
return nil
}