Added basic admin client
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/jackc/pgx/v4/pgxpool"
|
||||
"github.com/thequux/qddns/common"
|
||||
"github.com/thequux/qddns/db"
|
||||
_ "go.uber.org/zap"
|
||||
"net"
|
||||
"net/http"
|
||||
@@ -13,16 +12,11 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
var db *pgxpool.Pool
|
||||
|
||||
func main() {
|
||||
conn, err := pgxpool.Connect(context.Background(), os.Getenv("QDDNS_DB"))
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Unable to connect to database: %v")
|
||||
if err := db.Connect(""); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Unable to connect to database: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer conn.Close()
|
||||
db = conn
|
||||
|
||||
// Set up server
|
||||
r := gin.Default()
|
||||
@@ -47,7 +41,7 @@ func main() {
|
||||
}
|
||||
|
||||
// get a connection
|
||||
tx, err := db.Begin(c)
|
||||
tx, err := db.Db.Begin(c)
|
||||
defer tx.Rollback(c)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, common.Response{Status: "error", Message: "Failed to access database", Code: "QDE0001"})
|
||||
@@ -88,7 +82,7 @@ func main() {
|
||||
if tag.RowsAffected() != 1 {
|
||||
c.JSON(http.StatusInternalServerError, common.Response{
|
||||
Status: "error",
|
||||
Message: "Wrong number of rows affected: " + string(tag.RowsAffected()),
|
||||
Message: fmt.Sprintf("Wrong number of rows affected: %v", tag.RowsAffected()),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user