Description
I am trying to render a file into the body stream using (gin. context).File I cannot render the output file to my browser while getting a 404 page not found
error.
I am testing it in the incognito mode.
How to reproduce
func main() {
router := gin.Default()
router.StaticFile("/", "./index.html")
router.GET("/tale_of_two_cities", func(ctx *gin.Context) {
ctx.File("./two-cities.txt")
})
log.Fatal(router.Run(":3000"))
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name = "viewport" content="width=device-width, initial-scale=1.0">
<title>Book List</title>
</head>
<body>
<a href="./two-cities.txt">tale_of_two_cities</a><br/>
<a href="./data-rendering/expectations.txt"> Great Expectations</a>
</body>
</html>
Expectations
$ curl http://localhost:3000/two-cities.txt
Dickens opens the novel with a sentence that has become famous:
It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity, it was the season of Light, it was the season of Darkness, it was the spring of hope, it was the winter of despair, we had everything before us, we had nothing before us, we were all going direct to Heaven, we were all going direct the other way—in short, the period was so far like the present period, that some of its noisiest authorities insisted on its being received, for good or for evil, in the superlative degree of comparison only%
Actual result
$ curl http://localhost:3000/two-cities.txt
404 page not found%
Environment
- go version: 1.22.5
- gin version : github.com/gin-gonic/gin v1.10.0
- operating system: Mac OS