I want to respond with a bytes string using golang's framework gin [duplicate]

Server in Fastapi

async def thread(request):
    data = await request.body()
    return str(data)[2:-1]


@app.post("/stage1", response_class=HTMLResponse)
async def defend_stage_1(request: Request):
    return await thread(request)

As in the fastapi example above,
I want to respond with a bytes string by manipulating the bytes string in the request body.

the response i want

[POST] request body -> "ewogICAgIm5hbWUiOiAiYWRhbSIKfQ=="
response -> ewogICAgIm5hbWUiOiAiYWRhbSIKfQ==

enter image description here

Code i wrote

package main

import (
    "net/http"
    "fmt"
    "io/ioutil"
    "github.com/gin-gonic/gin"
    // "encoding/hex"
)

func getAlbums(c *gin.Context) {
    
    // body := c.Request.Body
    // fmt.Println(body)
    value, err := ioutil.ReadAll(c.Request.Body)
    // bodyString := string(value)
    fmt.Println(value, err)
    c.JSON(http.StatusOK, value)

}

func main() {
    router := gin.Default()
    router.POST("/albums", getAlbums)

    router.Run("localhost:8080")
}



Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation