refactor: use new struct in backend
This commit is contained in:
@@ -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.
|
||||
@@ -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 {
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package utils
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
Reference in New Issue
Block a user