util

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package util provides utility functions for the application

Index

Constants

This section is empty.

Variables

View Source
var (
	// BasePath The base path for the file storage
	BasePath string
)
View Source
var ErrInvalidAlgorithm = errors.New("invalid algorithm")

ErrInvalidAlgorithm The error for invalid algorithm

View Source
var ErrUnsafeNoneAlgorithm = errors.New("none algorithm is not supported for security reasons")

ErrUnsafeNoneAlgorithm The error for unsafe none algorithm

Functions

func ClarifyPath

func ClarifyPath(path string) (string, error)

ClarifyPath Ensures the path is valid and does not contain any path traversal

func FsPathToRelativePath

func FsPathToRelativePath(fsPath string) string

FsPathToRelativePath converts the real file system path to the relative path

func GetBasePath

func GetBasePath() string

GetBasePath Get the base path for the file storage

func GetPath

func GetPath(path string) string

GetPath Get the absolute path for the file storage

func GetUploadPath

func GetUploadPath() string

GetUploadPath Get the upload path for the file storage

func HeaderDateToInt64

func HeaderDateToInt64(date string) int64

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

func Int64ToHeaderDate(timestamp int64) string

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 JwtInit

func JwtInit()

JwtInit Initialize the JWT

func Match

func Match(pattern, name string) bool

Match the pattern with the name

func MatchMethod

func MatchMethod(method string, methods []string) bool

MatchMethod Match the method with the methods

func PathToRelativePath

func PathToRelativePath(path string) (string, error)

PathToRelativePath converts the absolute path provided to the relative path

func RandomString

func RandomString(length int) string

RandomString generates a random string of the specified length

func RelativeToFsPath

func RelativeToFsPath(path string) (string, error)

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

func ParseJwtToken(tokenString string) (*JwtClaims, error)

ParseJwtToken Parse the JWT token

func (*JwtClaims) Valid

func (c *JwtClaims) Valid() error

Valid The function to validate 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

func ParsePath

func ParsePath(path string) (*Path, error)

ParsePath Parse the path and return the absolute and relative paths

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL