Documentation
¶
Overview ¶
Package util provides utility functions for the application
Index ¶
- Variables
- func ClarifyPath(path string) (string, error)
- func FsPathToRelativePath(fsPath string) string
- func GetBasePath() string
- func GetPath(path string) string
- func GetUploadPath() string
- func HeaderDateToInt64(date string) int64
- func HeaderParseRangeDownload(rangeHeader string, fileSize int64) (start int64, end int64, err error)
- func HeaderParseRangeUpload(contentRange string, contentLength string) (start int64, end int64, total int64, err error)
- func Int64ToHeaderDate(timestamp int64) string
- func JwtInit()
- func Match(pattern, name string) bool
- func MatchMethod(method string, methods []string) bool
- func PathToRelativePath(path string) (string, error)
- func RandomString(length int) string
- func RelativeToFsPath(path string) (string, error)
- type JwtClaims
- type Path
- type Permission
Constants ¶
This section is empty.
Variables ¶
var ( // BasePath The base path for the file storage BasePath string )
var ErrInvalidAlgorithm = errors.New("invalid algorithm")
ErrInvalidAlgorithm The error for invalid algorithm
var ErrUnsafeNoneAlgorithm = errors.New("none algorithm is not supported for security reasons")
ErrUnsafeNoneAlgorithm The error for unsafe none algorithm
Functions ¶
func ClarifyPath ¶
ClarifyPath Ensures the path is valid and does not contain any path traversal
func FsPathToRelativePath ¶
FsPathToRelativePath converts the real file system path to the relative path
func GetUploadPath ¶
func GetUploadPath() string
GetUploadPath Get the upload path for the file storage
func HeaderDateToInt64 ¶
HeaderDateToInt64 converts a date string in the format "<day-name>, <day> <month> <year> <hour>:<minute>:<second> GMT" to an int64 representing the number of seconds since the Unix epoch.
func HeaderParseRangeDownload ¶
func HeaderParseRangeDownload(rangeHeader string, fileSize int64) (start int64, end int64, err error)
HeaderParseRangeDownload Parse the range header and return the start and end
func HeaderParseRangeUpload ¶
func HeaderParseRangeUpload(contentRange string, contentLength string) (start int64, end int64, total int64, err error)
HeaderParseRangeUpload Parse the range header and return the start and end
func Int64ToHeaderDate ¶
Int64ToHeaderDate converts an int64 representing the number of seconds since the Unix epoch to a date string in the format "<day-name>, <day> <month> <year> <hour>:<minute>:<second> GMT".
func MatchMethod ¶
MatchMethod Match the method with the methods
func PathToRelativePath ¶
PathToRelativePath converts the absolute path provided to the relative path
func RandomString ¶
RandomString generates a random string of the specified length
func RelativeToFsPath ¶
RelativeToFsPath converts the relative path provided to the real file system path
Types ¶
type JwtClaims ¶
type JwtClaims struct { *jwt.StandardClaims Permissions []Permission `json:"permissions"` // The permissions of the token }
JwtClaims The body of the JWT token
func ParseJwtToken ¶
ParseJwtToken Parse the JWT token
type Path ¶
type Path struct { // The absolute path of the file in the file system FsPath string `json:"fsPath"` // The relative path of the file RelativePath string `json:"relativePath"` // Cleaned path CleanedPath string `json:"cleanedPath"` }
Path is the structure for the file path
type Permission ¶
type Permission struct { Path string `json:"path"` // The path that the token is allowed to access, supports wildcards Methods []string `json:"methods"` // The methods that the token is allowed to access Query map[string]string `json:"query"` // The query parameters, if set in the map, the query should match the map }
Permission The permission of the token
Directories
¶
Path | Synopsis |
---|---|
Package base58 provides base58 encoding and decoding functions.
|
Package base58 provides base58 encoding and decoding functions. |
Package confutil provides the utility functions for the configuration
|
Package confutil provides the utility functions for the configuration |
Package hash provides a simple interface to hash strings and files using various algorithms.
|
Package hash provides a simple interface to hash strings and files using various algorithms. |
Package log provides a simple logging utility for the application.
|
Package log provides a simple logging utility for the application. |