Releases: rozdolsky33/toolkit
Releases · rozdolsky33/toolkit
Version v2.0.0 Release Notes
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
Initial release
Features Completed
- Read JSON
- Write JSON
- Produce a JSON encoded error response
- Upload files via HTTP requests with optional renaming and file type validation.
- Download a static file
- Get a random string of length n
- Post JSON to a remote service
- Create a directory, including all parent directories, if it does not already exist
- Create a URL-safe slug from a string