Sign inSign up

tgirgin/gin-gonic

By tgirgin

Updated almost 10 years ago

This container contains only gin-gonic and based on the golang container.

Image
0

1.0K

tgirgin/gin-gonic repository overview

To get this container up and running with a simple example, just bash into the container (docker exec -it nameOfContainer /bin/bash) and navigate to /go/public to add a go file (e.g., main.go).

Add the following code to your main.go file:

package main

import ( "net/http"

"github.com/gin-gonic/gin"

)

var router *gin.Engine

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

// This handler will match /user/john but will not match neither /user/ or /user
router.GET("/user/:name", func(c *gin.Context) {
	name := c.Param("name")
	c.String(http.StatusOK, "Hello %s", name)
})

// However, this one will match /user/john/ and also /user/john/send
// If no other routers match /user/john, it will redirect to /user/john/
router.GET("/user/:name/*action", func(c *gin.Context) {
	name := c.Param("name")
	action := c.Param("action")
	message := name + " is " + action
	c.String(http.StatusOK, message)
})

router.Run(":8080")

}

Save your code, and type: "go run main.go"

You can then navigate to http://localhost:8080/user/myUsername

Tag summary

Content type

Image

Digest

Size

262 MB

Last updated

almost 10 years ago

docker pull tgirgin/gin-gonic