basic setup

This commit is contained in:
jotty
2026-05-23 09:55:03 +02:00
parent f563e87f07
commit c257151fbb
4 changed files with 146 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
package main
import (
"net/http"
"github.com/gin-gonic/gin"
)
type EchoRequest struct {
Message string `json:"message" binding:"required"`
}
func main() {
r := gin.Default()
// GET /ping
r.GET("/ping", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"message": "pong"})
})
// POST /echo
r.POST("/echo", func(c *gin.Context) {
var req EchoRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{"echo": req.Message})
})
// Server starten auf Port 8080
r.Run(":8080")
}