Route parameters

Report a typo

Create a web server that supports a nested route consisting of two levels (e.g., /api/ping, where /api is the first level and /ping is the second). The URI parameters should define the names of the levels.

The route handler must read the level names and respond with a string that contains the names of the routes separated by a dot. For example, if you request the route /user/get, it must respond with the string "user.get".

After creating the route, launch a web server that listens on the address 127.0.0.1:8080, serving the previously created route.

Write a program in Go
package main

import (
"fmt"
"io"
"net/http"
"time"

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

type Endpoint struct {
? string `uri:"method"`
? string ?
}

func main() {
// DO NOT delete the two lines below! They disable Gin's debug mode to check your solution
gin.SetMode(gin.ReleaseMode)
gin.DefaultWriter = io.Discard

router := gin.Default()

router.GET("/:method/:argument", func(context *gin.Context) {
var endpoint ?

err := context.ShouldBindUri(&endpoint)
if err != nil {
context.String(http.StatusBadRequest, "error")
return
}

context.String(http.StatusOK, "%s.%s", ?, ?)
})

go func() { // DO NOT delete this line of code
___

Create a free account to access the full topic