Fixed version and reset-db issue
This commit is contained in:
+4
-10
@@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
@@ -20,19 +19,14 @@ import (
|
||||
"git.kundeng.us/phoenix/textsender-auth/internal/handler/endpoint"
|
||||
mdleware "git.kundeng.us/phoenix/textsender-auth/internal/middleware"
|
||||
"git.kundeng.us/phoenix/textsender-auth/internal/model"
|
||||
"git.kundeng.us/phoenix/textsender-auth/internal/version"
|
||||
)
|
||||
|
||||
func main() {
|
||||
versionFlag := flag.Bool("version", false, "Print version information")
|
||||
flag.Parse()
|
||||
if *versionFlag {
|
||||
fmt.Println(version.String())
|
||||
return
|
||||
}
|
||||
fmt.Println(config.App_Name)
|
||||
|
||||
cfg := config.Load()
|
||||
if cfg == nil {
|
||||
fmt.Println("Error initializing config")
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
db, err := db.NewDatabase(cfg.GetDBConnString())
|
||||
if err != nil {
|
||||
|
||||
@@ -8,6 +8,8 @@ import (
|
||||
"strconv"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
|
||||
"git.kundeng.us/phoenix/textsender-auth/internal/version"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -33,11 +35,22 @@ func (ci ConnectionInfo) Parse() string {
|
||||
return fmt.Sprintf("postgres://%s:%s@%s:%d/%s?sslmode=%s", ci.Username, ci.Password, ci.Host, ci.Port, ci.Database, ci.SslMode)
|
||||
}
|
||||
|
||||
func PrintName() {
|
||||
fmt.Println(App_Name)
|
||||
fmt.Println(version.String())
|
||||
}
|
||||
|
||||
func Load() *Config {
|
||||
versionFlag := flag.Bool("version", false, "Print version information")
|
||||
resetDb := flag.Bool("reset-db", false, "Reset the database schema and exit")
|
||||
port := flag.String("port", Port, "Server port")
|
||||
flag.Parse()
|
||||
|
||||
if *versionFlag {
|
||||
fmt.Println(version.String())
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
err := godotenv.Load()
|
||||
if err != nil {
|
||||
log.Fatal("Error loading .env file")
|
||||
|
||||
Reference in New Issue
Block a user