package project import ( "fmt" "github.com/gin-gonic/gin" "io" "net/http" "os" ) func peopleMsg(c *gin.Context) { file, err := os.Open("people.xls") if err != nil { c.JSON(http.StatusNotFound, gin.H{ "result": "文件加载失败" + fmt.Sprintf("%s", err), }) fmt.Printf("%s", err) return } defer file.Close() c.Writer.Header().Add("Content-Type", "application/octet-stream") _, err = io.Copy(c.Writer, file) if err != nil { c.JSON(http.StatusNotFound, gin.H{ "result": "文件加载失败" + fmt.Sprintf("%s", err), }) fmt.Printf("%s", err) return } } func projectMsg(c *gin.Context) { file, err := os.Open("project.xls") if err != nil { c.JSON(http.StatusNotFound, gin.H{ "result": "文件加载失败" + fmt.Sprintf("%s", err), }) fmt.Printf("%s", err) return } defer file.Close() c.Writer.Header().Add("Content-Type", "application/octet-stream") _, err = io.Copy(c.Writer, file) if err != nil { c.JSON(http.StatusNotFound, gin.H{ "result": "文件加载失败" + fmt.Sprintf("%s", err), }) fmt.Printf("%s", err) return } }