Skip to content

Commit

Permalink
chore: format
Browse files Browse the repository at this point in the history
  • Loading branch information
gabeklavans committed Feb 27, 2024
1 parent 635c2a5 commit 2bf7314
Showing 1 changed file with 35 additions and 35 deletions.
70 changes: 35 additions & 35 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,61 +6,61 @@ import (
"net/http"
"os"

"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
"github.com/gin-contrib/cors"
"github.com/joho/godotenv"
)

type ListingProps struct {
Refs []string `json:"refs"`
Price int `json:"price"`
Beds float32 `json:"beds"`
Baths float32 `json:"baths"`
Date string `json:"date"`
Notes string `json:"notes"`
IsFavorite bool `json:"isFavorite"`
IsDismissed bool `json:"isDismissed"`
Refs []string `json:"refs"`
Price int `json:"price"`
Beds float32 `json:"beds"`
Baths float32 `json:"baths"`
Date string `json:"date"`
Notes string `json:"notes"`
IsFavorite bool `json:"isFavorite"`
IsDismissed bool `json:"isDismissed"`
}

func basicAuth(c *gin.Context) {
user, password, hasAuth := c.Request.BasicAuth()
if hasAuth && user == os.Getenv("AUTH_USER") && password == os.Getenv("AUTH_PASS") {
c.Next()
} else {
c.Abort()
c.JSON(http.StatusUnauthorized, gin.H{"error": "Unauthorized"})
return
}
user, password, hasAuth := c.Request.BasicAuth()
if hasAuth && user == os.Getenv("AUTH_USER") && password == os.Getenv("AUTH_PASS") {
c.Next()
} else {
c.Abort()
c.JSON(http.StatusUnauthorized, gin.H{"error": "Unauthorized"})
return
}
}

func getListings(c *gin.Context) {
data, err := os.ReadFile("../data/listings.json")
if err != nil {
log.Print(err)
}
data, err := os.ReadFile("../data/listings.json")
if err != nil {
log.Print(err)
}

m := make(map[string]ListingProps)
json.Unmarshal(data, &m)
m := make(map[string]ListingProps)
json.Unmarshal(data, &m)

c.IndentedJSON(http.StatusOK, m)
c.IndentedJSON(http.StatusOK, m)
}

func ping(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"pong": true})
c.JSON(http.StatusOK, gin.H{"pong": true})
}

func main() {
err := godotenv.Load("../.env")
if err != nil {
log.Fatalf("Error loading .env: %s", err)
}
err := godotenv.Load("../.env")
if err != nil {
log.Fatalf("Error loading .env: %s", err)
}

router := gin.Default()
router := gin.Default()

router.Use(cors.Default())
router.Use(cors.Default())

router.GET("/ping", basicAuth, ping)
router.GET("/listings", getListings)
router.GET("/ping", basicAuth, ping)
router.GET("/listings", getListings)

router.Run("192.168.88.22:8083")
router.Run("192.168.88.22:8083")
}

0 comments on commit 2bf7314

Please sign in to comment.