switch command line args
This commit is contained in:
parent
89aadbf31a
commit
9b03c64577
2
Makefile
2
Makefile
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
sync-run:
|
sync-run:
|
||||||
cd sync/service && PLANNER_DB_HOST=localhost PLANNER_DB_PORT=5432 PLANNER_DB_NAME=planner PLANNER_DB_USER=test PLANNER_DB_PASSWORD=test PLANNER_PORT=8092 PLANNER_API_KEY=testKey go run .
|
cd sync/service && go run . -dbname localhost -dbport 5432 -dbname planner -dbuser test -dbpassword test -port 8092 -key testKey
|
||||||
|
|
||||||
database:
|
database:
|
||||||
docker run -e POSTGRES_USER=test -e POSTGRES_PASSWORD=test -e POSTGRES_DB=planner -p 5432:5432 postgres:16
|
docker run -e POSTGRES_USER=test -e POSTGRES_PASSWORD=test -e POSTGRES_DB=planner -p 5432:5432 postgres:16
|
||||||
|
|
|
@ -1,50 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log/slog"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"os/signal"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
port := os.Getenv("PLANNER_PORT")
|
|
||||||
apiKey := os.Getenv("PLANNER_API_KEY")
|
|
||||||
if apiKey == "" {
|
|
||||||
fmt.Println("PLANNER_API_KEY is empty")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
dbHost := os.Getenv("PLANNER_DB_HOST")
|
|
||||||
dbPort := os.Getenv("PLANNER_DB_PORT")
|
|
||||||
dbName := os.Getenv("PLANNER_DB_NAME")
|
|
||||||
dbUser := os.Getenv("PLANNER_DB_USER")
|
|
||||||
dbPassword := os.Getenv("PLANNER_DB_PASSWORD")
|
|
||||||
repo, err := NewPostgres(dbHost, dbPort, dbName, dbUser, dbPassword)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("could not open sqlite db: %s", err.Error())
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
|
|
||||||
logger.Info("configuration", "configuration", map[string]string{
|
|
||||||
"port": port,
|
|
||||||
"dbHost": dbHost,
|
|
||||||
"dbPort": dbPort,
|
|
||||||
"dbName": dbName,
|
|
||||||
"dbUser": dbUser,
|
|
||||||
})
|
|
||||||
|
|
||||||
srv := NewServer(repo, apiKey, logger)
|
|
||||||
go http.ListenAndServe(fmt.Sprintf(":%s", port), srv)
|
|
||||||
|
|
||||||
logger.Info("service started")
|
|
||||||
|
|
||||||
c := make(chan os.Signal, 1)
|
|
||||||
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
|
|
||||||
<-c
|
|
||||||
|
|
||||||
logger.Info("service stopped")
|
|
||||||
}
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
apiPort = flag.String("port", "8092", "api port")
|
||||||
|
apiKey = flag.String("key", "testKey", "api key")
|
||||||
|
dbHost = flag.String("dbhost", "localhost", "database host")
|
||||||
|
dbPort = flag.String("dbport", "5432", "database port")
|
||||||
|
dbName = flag.String("dbname", "planner", "database name")
|
||||||
|
dbUser = flag.String("dbuser", "test", "database user")
|
||||||
|
dbPassword = flag.String("dbpassword", "test", "database password")
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
repo, err := NewPostgres(*dbHost, *dbPort, *dbName, *dbUser, *dbPassword)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("could not open postgres db: %s", err.Error())
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
|
||||||
|
logger.Info("configuration", "configuration", map[string]string{
|
||||||
|
"port": *apiPort,
|
||||||
|
"dbHost": *dbHost,
|
||||||
|
"dbPort": *dbPort,
|
||||||
|
"dbName": *dbName,
|
||||||
|
"dbUser": *dbUser,
|
||||||
|
})
|
||||||
|
|
||||||
|
srv := NewServer(repo, *apiKey, logger)
|
||||||
|
go http.ListenAndServe(fmt.Sprintf(":%s", *apiPort), srv)
|
||||||
|
|
||||||
|
logger.Info("service started")
|
||||||
|
|
||||||
|
c := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
|
||||||
|
<-c
|
||||||
|
|
||||||
|
logger.Info("service stopped")
|
||||||
|
}
|
Loading…
Reference in New Issue