feat:add robots.txt

This commit is contained in:
samwaf
2024-10-24 08:44:56 +08:00
parent 049daba1e6
commit 18dbcd4818

View File

@@ -59,6 +59,19 @@ func Static(r *gin.Engine, noRoute func(handlers ...gin.HandlerFunc)) {
c.Status(http.StatusOK)
_, _ = io.Copy(c.Writer, faviconFile)
})
r.GET("/robots.txt", func(c *gin.Context) {
robotFile, err := static.Open("robots.txt")
if err != nil {
zlog.Error("can't find robots.txt")
c.Status(http.StatusNotFound)
return
}
defer robotFile.Close()
c.Header("Content-Type", "text/plain")
c.Status(http.StatusOK)
_, _ = io.Copy(c.Writer, robotFile)
})
noRoute(func(c *gin.Context) {
c.Header("Content-Type", "text/html")