v2.0.0 Release Notes
New Features
-
DownloadStaticFile Function
- Added a new method
DownloadStaticFile
to theTools
struct for downloading files. This method sets theContent-Disposition
header to "attachment" to force file download rather than display in the browser. Additionally, it allows for a specified display name.func (t *Tools) DownloadStaticFile(w http.ResponseWriter, r *http.Request, pathName, displayName string) { w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", displayName)) http.ServeFile(w, r, pathName) }
- Added a new method
-
JSONResponse Struct
- Introduced the
JSONResponse
struct for a standardized format of JSON responses. It includes fields for:Error
(a boolean indicating if there is an error)Message
(a string for the message)Data
(an optional field for additional data)
type JSONResponse struct { Error bool `json:"error"` Message string `json:"message"` Data interface{} `json:"data,omitempty"` }
- Introduced the