~blu/dip

68aa9ef11c129f561bbcc4d0c5f8af69992a0b61 — Bryant Conquest 1 year, 10 months ago 2d0dfc2
allow all origins for cors
2 files changed, 12 insertions(+), 9 deletions(-)

M go.mod
M main.go
M go.mod => go.mod +3 -2
@@ 3,13 3,13 @@ module paxavis.dev/dip
go 1.18

require (
	github.com/BurntSushi/toml v1.1.0
	github.com/jackc/pgx/v4 v4.16.1
	github.com/jackc/pgx/v5 v5.0.0-alpha.5
	github.com/labstack/echo/v4 v4.7.2
)

require (
	github.com/BurntSushi/toml v1.1.0 // indirect
	github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
	github.com/jackc/chunkreader/v2 v2.0.1 // indirect
	github.com/jackc/pgconn v1.12.1 // indirect
	github.com/jackc/pgio v1.0.0 // indirect


@@ 28,4 28,5 @@ require (
	golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
	golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
	golang.org/x/text v0.3.7 // indirect
	golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 // indirect
)

M main.go => main.go +9 -7
@@ 13,6 13,7 @@ import (
	_ "github.com/jackc/pgx/v4"
	"github.com/jackc/pgx/v4/pgxpool"
	"github.com/labstack/echo/v4"
	"github.com/labstack/echo/v4/middleware"

	"paxavis.dev/dip/search"
	"paxavis.dev/dip/sources"


@@ 28,21 29,21 @@ type Config struct {

func (c Client) checkip(ctx echo.Context) error {
	ip := ctx.QueryParam("ip")
  v := map[string]any{
    "error": nil,
    "result": nil,
  }
	v := map[string]any{
		"error":  nil,
		"result": nil,
	}
	found, data, err := search.Search(ctx.Request().Context(), c.DB, ip)
	if err != nil {
		log.Println(err)
    v["error"] = fmt.Sprintf("error running query for ip: %s", ip)
		v["error"] = fmt.Sprintf("error running query for ip: %s", ip)
		return ctx.JSON(http.StatusInternalServerError, v)
	}
	if !found {
    v["error"] = fmt.Sprintf("ip `%s` not found", ip)
		v["error"] = fmt.Sprintf("ip `%s` not found", ip)
		return ctx.JSON(http.StatusNotFound, v)
	}
  v["result"] = data
	v["result"] = data
	return ctx.JSON(http.StatusOK, v)
}



@@ 150,6 151,7 @@ func main() {
		}
	default:
		e := echo.New()
		e.Use(middleware.CORS())
		e.GET("/checkip", client.checkip)
		e.Logger.Fatal(e.Start(":8080"))
	}