From 1cc6b7b1bafb56d7cf862797bf7a0b8c86deeb98 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Wed, 15 Jul 2026 11:08:45 +0800 Subject: [PATCH] refactor: use new struct in backend --- backend/{ => cli}/cli.go | 6 +++--- backend/{ => config}/config.go | 12 ++++++------ backend/main.go | 7 +++++-- backend/{ => utils}/utils.go | 2 +- 4 files changed, 15 insertions(+), 12 deletions(-) rename backend/{ => cli}/cli.go (91%) rename backend/{ => config}/config.go (91%) rename backend/{ => utils}/utils.go (99%) diff --git a/backend/cli.go b/backend/cli/cli.go similarity index 91% rename from backend/cli.go rename to backend/cli/cli.go index 44ab26f..aa8b5f7 100644 --- a/backend/cli.go +++ b/backend/cli/cli.go @@ -1,4 +1,4 @@ -package main +package cli import ( "flag" @@ -15,10 +15,10 @@ type CLIArgs struct { Init bool } -// ParseCLI parses the command-line arguments via the standard flag package and +// Parse parses the command-line arguments via the standard flag package and // returns a *CLIArgs. When the required --config flag is missing, it prints the // usage and exits with status 2 (matching argparse's exit code). -func ParseCLI() *CLIArgs { +func Parse() *CLIArgs { args := &CLIArgs{} // Custom usage output mirroring the legacy ArgumentParser description banner. diff --git a/backend/config.go b/backend/config/config.go similarity index 91% rename from backend/config.go rename to backend/config/config.go index e1708ba..b97863e 100644 --- a/backend/config.go +++ b/backend/config/config.go @@ -1,4 +1,4 @@ -package main +package config import ( "fmt" @@ -107,12 +107,12 @@ type rawConfig struct { Others OthersConfig `toml:"others"` } -// LoadConfig reads and parses the TOML config file at the given path, returning -// the parsed config or an error. It merges the legacy setup_config and -// get_config: the first phase uses toml.DecodeFile to defer database.config, and -// the second phase dispatches PrimitiveDecode into SqliteDatabaseConfig or +// Load reads and parses the TOML config file at the given path, returning the +// parsed config or an error. It merges the legacy setup_config and get_config: +// the first phase uses toml.DecodeFile to defer database.config, and the second +// phase dispatches PrimitiveDecode into SqliteDatabaseConfig or // MysqlDatabaseConfig based on the driver. -func LoadConfig(path string) (*Config, error) { +func Load(path string) (*Config, error) { var raw rawConfig meta, err := toml.DecodeFile(path, &raw) if err != nil { diff --git a/backend/main.go b/backend/main.go index ee7ea8c..6333f52 100644 --- a/backend/main.go +++ b/backend/main.go @@ -6,12 +6,15 @@ import ( "net/http" "github.com/gin-gonic/gin" + + "github.com/yyc12345/coconut-leaf/backend/cli" + "github.com/yyc12345/coconut-leaf/backend/config" ) func main() { - args := ParseCLI() + args := cli.Parse() - cfg, err := LoadConfig(args.Config) + cfg, err := config.Load(args.Config) if err != nil { log.Fatal(err) } diff --git a/backend/utils.go b/backend/utils/utils.go similarity index 99% rename from backend/utils.go rename to backend/utils/utils.go index 8d56476..a124464 100644 --- a/backend/utils.go +++ b/backend/utils/utils.go @@ -1,4 +1,4 @@ -package main +package utils import ( "crypto/sha256"