Fixed version and reset-db issue
This commit is contained in:
+4
-10
@@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"flag"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -20,19 +19,14 @@ import (
|
|||||||
"git.kundeng.us/phoenix/textsender-auth/internal/handler/endpoint"
|
"git.kundeng.us/phoenix/textsender-auth/internal/handler/endpoint"
|
||||||
mdleware "git.kundeng.us/phoenix/textsender-auth/internal/middleware"
|
mdleware "git.kundeng.us/phoenix/textsender-auth/internal/middleware"
|
||||||
"git.kundeng.us/phoenix/textsender-auth/internal/model"
|
"git.kundeng.us/phoenix/textsender-auth/internal/model"
|
||||||
"git.kundeng.us/phoenix/textsender-auth/internal/version"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
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()
|
cfg := config.Load()
|
||||||
|
if cfg == nil {
|
||||||
|
fmt.Println("Error initializing config")
|
||||||
|
os.Exit(-1)
|
||||||
|
}
|
||||||
|
|
||||||
db, err := db.NewDatabase(cfg.GetDBConnString())
|
db, err := db.NewDatabase(cfg.GetDBConnString())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/textsender-auth/internal/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
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)
|
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 {
|
func Load() *Config {
|
||||||
|
versionFlag := flag.Bool("version", false, "Print version information")
|
||||||
resetDb := flag.Bool("reset-db", false, "Reset the database schema and exit")
|
resetDb := flag.Bool("reset-db", false, "Reset the database schema and exit")
|
||||||
port := flag.String("port", Port, "Server port")
|
port := flag.String("port", Port, "Server port")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
if *versionFlag {
|
||||||
|
fmt.Println(version.String())
|
||||||
|
os.Exit(-1)
|
||||||
|
}
|
||||||
|
|
||||||
err := godotenv.Load()
|
err := godotenv.Load()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error loading .env file")
|
log.Fatal("Error loading .env file")
|
||||||
|
|||||||
Reference in New Issue
Block a user