mirror of
https://github.com/aykhans/slash-e.git
synced 2025-07-19 19:24:01 +00:00
feat: refactor code structure
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user