This commit is contained in:
George Shammas 2022-01-04 17:07:48 -05:00
parent 984be2f57e
commit b91d8b5fda
1 changed files with 14 additions and 14 deletions

28
main.go
View File

@ -1,15 +1,15 @@
package main package main
import ( import (
"encoding/json"
"fmt" "fmt"
"github.com/gin-gonic/gin"
proxyproto "github.com/pires/go-proxyproto"
"net" "net"
"os" "os"
"strconv" "strconv"
"strings" "strings"
"time" "time"
"encoding/json"
"github.com/gin-gonic/gin"
proxyproto "github.com/pires/go-proxyproto"
) )
type Configuration struct { type Configuration struct {
@ -157,13 +157,13 @@ func mainHandler(c *gin.Context) {
} }
return return
case "headers": case "headers":
if wantsJS { if wantsJS {
c.Writer.Header().Set("Content-Type", "application/javascript") c.Writer.Header().Set("Content-Type", "application/javascript")
response, _ := json.Marshal(c.Request.Header) response, _ := json.Marshal(c.Request.Header)
c.String(200, "ifconfig_io = %v\n", string(response)) c.String(200, "ifconfig_io = %v\n", string(response))
} else { } else {
c.JSON(200, c.Request.Header) c.JSON(200, c.Request.Header)
} }
return return
} }
fieldResult, exists := c.Get(fields[0]) fieldResult, exists := c.Get(fields[0])
@ -174,10 +174,10 @@ func mainHandler(c *gin.Context) {
if wantsJSON { if wantsJSON {
c.JSON(200, fieldResult) c.JSON(200, fieldResult)
} else if wantsJS { } else if wantsJS {
c.Writer.Header().Set("Content-Type", "application/javascript") c.Writer.Header().Set("Content-Type", "application/javascript")
response, _ := json.Marshal(map[string]interface{}{fields[0]: fieldResult}) response, _ := json.Marshal(map[string]interface{}{fields[0]: fieldResult})
c.String(200, "ifconfig_io = %v\n", string(response)) c.String(200, "ifconfig_io = %v\n", string(response))
} else { } else {
c.String(200, fmt.Sprintln(fieldResult)) c.String(200, fmt.Sprintln(fieldResult))
} }