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 (
"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.

View File

@@ -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 {

View File

@@ -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)
}

View File

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