A couple of minor changes

This commit is contained in:
2022-08-06 14:19:18 +02:00
parent aa7a98f984
commit 9759778a0c
4 changed files with 61 additions and 6 deletions

View File

@@ -5,7 +5,7 @@ import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/jackc/pgx/v4/pgxpool"
"github.com/thequux/pdns-auto-update/common"
"github.com/thequux/qddns/common"
_ "go.uber.org/zap"
"net"
"net/http"
@@ -18,7 +18,7 @@ var db *pgxpool.Pool
func main() {
conn, err := pgxpool.Connect(context.Background(), os.Getenv("QDDNS_DB"))
if err != nil {
fmt.Fprintf(os.Stderr, "Unabled to connect to database: %v")
fmt.Fprintf(os.Stderr, "Unable to connect to database: %v")
os.Exit(1)
}
defer conn.Close()
@@ -28,7 +28,7 @@ func main() {
r := gin.Default()
r.POST("/update/:domain", func(c *gin.Context) {
authHdr := strings.Fields(c.GetHeader("Authorization"))
domain := c.Param("domain");
domain := c.Param("domain")
clientIP := c.ClientIP()
ip := net.ParseIP(clientIP)
@@ -54,7 +54,7 @@ func main() {
return
}
// check token validity
row := tx.QueryRow(c, "SELECT COUNT(*) from qddns_auth WHERE token = $1 AND domain = $2", token, domain);
row := tx.QueryRow(c, "SELECT COUNT(*) from qddns_auth WHERE token = $1 AND domain = $2", token, domain)
var rcount int
if err := row.Scan(&rcount); err != nil {
c.JSON(http.StatusInternalServerError, common.Response{Status: "error", Message: "Failed to check token " + err.Error(), Code: "QDE0002"})