feat: refactor code structure

This commit is contained in:
Steven
2023-02-23 08:22:06 +08:00
parent f77a84a649
commit 0fbbcae872
36 changed files with 768 additions and 936 deletions

View File

@@ -1,13 +1,13 @@
package profile
import (
"flag"
"fmt"
"os"
"path/filepath"
"strings"
"github.com/boojack/corgi/server/version"
"github.com/spf13/viper"
)
// Profile is the configuration to start main server.
@@ -47,10 +47,10 @@ func checkDSN(dataDir string) (string, error) {
// GetDevProfile will return a profile for dev or prod.
func GetProfile() (*Profile, error) {
profile := Profile{}
flag.StringVar(&profile.Mode, "mode", "dev", "mode of server")
flag.IntVar(&profile.Port, "port", 8081, "port of server")
flag.StringVar(&profile.Data, "data", "", "data directory")
flag.Parse()
err := viper.Unmarshal(&profile)
if err != nil {
return nil, err
}
if profile.Mode != "dev" && profile.Mode != "prod" {
profile.Mode = "dev"
@@ -69,6 +69,5 @@ func GetProfile() (*Profile, error) {
profile.Data = dataDir
profile.DSN = fmt.Sprintf("%s/corgi_%s.db", dataDir, profile.Mode)
profile.Version = version.GetCurrentVersion(profile.Mode)
return &profile, nil
}