Got everything working

This commit is contained in:
2022-08-06 18:25:07 +02:00
parent ad706b5c37
commit 01c80e1f83

View File

@@ -15,14 +15,12 @@ import (
func Update(c *gin.Context) {
authHdr := strings.Fields(c.GetHeader("Authorization"))
fmt.Printf("Header: %q\n", c.GetHeader("Authorization"))
fmt.Println("Split: %q\n", authHdr)
domain := c.Param("domain")
clientIP := c.ClientIP()
clientIP := c.GetHeader("X-Real-IP")
ip := net.ParseIP(clientIP)
var token string
if len(authHdr) == 0 || authHdr[0] != "bearer" {
if len(authHdr) == 2 && authHdr[0] == "bearer" {
// we have a token; check if it's valid for domain
token = authHdr[1]
} else {
@@ -65,7 +63,7 @@ func Update(c *gin.Context) {
}
// Do the update
tag, err := tx.Exec(c, "UPDATE records SET content = $1 WHERE domain = $2 AND type = $3", clientIP, domain, recordType)
tag, err := tx.Exec(c, "UPDATE records SET content = $1 WHERE name = $2 AND type = $3", clientIP, domain, recordType)
if err != nil {
c.JSON(http.StatusInternalServerError, common.Response{
Status: "error",