1
0

refactor: use new struct in backend

This commit is contained in:
2026-07-15 11:08:45 +08:00
parent a8de650a5a
commit 1cc6b7b1ba
4 changed files with 15 additions and 12 deletions

View File

@@ -1,4 +1,4 @@
package main package cli
import ( import (
"flag" "flag"
@@ -15,10 +15,10 @@ type CLIArgs struct {
Init bool 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 // returns a *CLIArgs. When the required --config flag is missing, it prints the
// usage and exits with status 2 (matching argparse's exit code). // usage and exits with status 2 (matching argparse's exit code).
func ParseCLI() *CLIArgs { func Parse() *CLIArgs {
args := &CLIArgs{} args := &CLIArgs{}
// Custom usage output mirroring the legacy ArgumentParser description banner. // Custom usage output mirroring the legacy ArgumentParser description banner.

View File

@@ -1,4 +1,4 @@
package main package config
import ( import (
"fmt" "fmt"
@@ -107,12 +107,12 @@ type rawConfig struct {
Others OthersConfig `toml:"others"` Others OthersConfig `toml:"others"`
} }
// LoadConfig reads and parses the TOML config file at the given path, returning // Load reads and parses the TOML config file at the given path, returning the
// the parsed config or an error. It merges the legacy setup_config and // parsed config or an error. It merges the legacy setup_config and get_config:
// get_config: the first phase uses toml.DecodeFile to defer database.config, and // the first phase uses toml.DecodeFile to defer database.config, and the second
// the second phase dispatches PrimitiveDecode into SqliteDatabaseConfig or // phase dispatches PrimitiveDecode into SqliteDatabaseConfig or
// MysqlDatabaseConfig based on the driver. // MysqlDatabaseConfig based on the driver.
func LoadConfig(path string) (*Config, error) { func Load(path string) (*Config, error) {
var raw rawConfig var raw rawConfig
meta, err := toml.DecodeFile(path, &raw) meta, err := toml.DecodeFile(path, &raw)
if err != nil { if err != nil {

View File

@@ -6,12 +6,15 @@ import (
"net/http" "net/http"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/yyc12345/coconut-leaf/backend/cli"
"github.com/yyc12345/coconut-leaf/backend/config"
) )
func main() { func main() {
args := ParseCLI() args := cli.Parse()
cfg, err := LoadConfig(args.Config) cfg, err := config.Load(args.Config)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@@ -1,4 +1,4 @@
package main package utils
import ( import (
"crypto/sha256" "crypto/sha256"