mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-23 17:31:11 +01:00
detail:
1. add utils.BytesToString function instead of string() convert bytes to string.
2. use bytes.NewReader instead of strings.NewReader(string(sb)).
3. use w.Body.Bytes() instead of []byte(w.Body.String()).
22 lines
390 B
Go
22 lines
390 B
Go
package routes
|
|
|
|
import (
|
|
"crawlab/utils"
|
|
"github.com/gin-gonic/gin"
|
|
"io/ioutil"
|
|
"net/http"
|
|
)
|
|
|
|
func GetFile(c *gin.Context) {
|
|
path := c.Query("path")
|
|
fileBytes, err := ioutil.ReadFile(path)
|
|
if err != nil {
|
|
HandleError(http.StatusInternalServerError, c, err)
|
|
}
|
|
c.JSON(http.StatusOK, Response{
|
|
Status: "ok",
|
|
Message: "success",
|
|
Data: utils.BytesToString(fileBytes),
|
|
})
|
|
}
|