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