File: gin.go

package info (click to toggle)
golang-github-appleboy-gofight 2.1.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 212 kB
  • sloc: makefile: 50
file content (28 lines) | stat: -rw-r--r-- 465 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package example

import (
	"fmt"
	"net/http"

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

func ginHelloHandler(c *gin.Context) {
	c.String(http.StatusOK, "Hello World")
}

func ginUserHandler(c *gin.Context) {
	name := c.Param("name")
	c.String(http.StatusOK, fmt.Sprintf("Hello, %s", name))
}

// GinEngine is gin router.
func GinEngine() *gin.Engine {
	gin.SetMode(gin.TestMode)
	r := gin.New()

	r.GET("/", ginHelloHandler)
	r.GET("/user/:name", ginUserHandler)

	return r
}