Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
IT Security DownloadsGitHub Release: openclaw/openclaw v2026.7.35 (20.09.2026)(20.09.2026 um 21:37 Uhr)
IT Security DownloadsGitHub Release: openclaw/openclaw v2026.7.35 (20.09.2026)(20.09.2026 um 21:37 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Gin and router example

Reagiere als Erste:r — dein Feedback zählt!

Image description

  • Install Gin with the following command:
go get -u github.com/gin-gonic/gin
  • After installation, we proceed to code in the “main.go” file with a simple function as follows:
package main

import (
  "net/http"

  "github.com/gin-gonic/gin"
)

func main() {
  r := gin.Default()
  r.GET("/ping", func(c *gin.Context) {
    c.JSON(http.StatusOK, gin.H{
      "message": "pong",
    })
  })
  r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}

  • Then run the main file with the following command:
go run cmd/server/main.go

Note: Depending on your folder organization, the command to run the main.go file may differ from mine. I have introduced how to organize the structure in the article: here

  • After running the above command, we will receive the following result:

Image description

  • Great, let's try calling the ping endpoint with the following command:
curl http://localhost:8080/ping
  • The result received will be:

Image description

  • Now, let's try to split the simple router:
package main

import (
    "net/http"

    "github.com/gin-gonic/gin"
)

func main() {
    r := gin.Default()

    v1 := r.Group("/v1")
    {
        v1.GET("/ping", Pong) // curl http://localhost:8080/v1/ping
    }
    r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}

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

Note: After changing the code as above, remember to run the command: "go run cmd/server/main.go" to apply the new code.

  • Next, let's try running the new router with the following command:
curl http://localhost:8080/v1/ping
  • The result received will be:

Image description

  • Now, let's try to get the parameter from Param:
package main

import (
    "net/http"

    "github.com/gin-gonic/gin"
)

func main() {
    r := gin.Default()

    v1 := r.Group("/v1")
    {
        v1.GET("/ping/:name", Pong) // curl http://localhost:8080/v1/ping
    }
    r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}

func Pong(c *gin.Context) {
    name := c.Param("name")
    c.JSON(http.StatusOK, gin.H{
        "message": "pong:::: " + name,
    })
}

Note: After changing the code as above, remember to run the command: "go run cmd/server/main.go" to apply the new code.

  • Try to get the param with the following command:
curl http://localhost:8080/v1/ping/hieunguyen
  • The result received will be:

Image description

  • Next, we will try to get the parameter from the Query:
package main

import (
    "net/http"

    "github.com/gin-gonic/gin"
)

func main() {
    r := gin.Default()

    v1 := r.Group("/v1")
    {
        v1.GET("/ping", Pong) // curl http://localhost:8080/v1/ping
    }
    r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}

func Pong(c *gin.Context) {
    id := c.Query("id")
    c.JSON(http.StatusOK, gin.H{
        "message": "pong:::: " + id,
    })
}

Note: After changing the code as above, remember to run the command: "go run cmd/server/main.go" to apply the new code.

  • Try to get the query with the following command:
curl http://localhost:8080/v1/ping\?id=12345
  • The result received will be:

Image description

You can directly refer to Gin on GitHub with the following link:here

Give me a reaction and a follow for motivation 😘

If you found this article useful and interesting, please share it with your friends and family. I hope you found it helpful. Thanks for reading 🙏

Let's get connected! You can find me on:

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Gin and router example

Thematisch verwandte Begriffe: router, example · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-93956 | A flaw has been found in olivier-ls PHP-FTS up to 1.1.2. Affected by thi…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick