util

package
v7.6.74 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: GPL-3.0 Imports: 16 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DumpRequest

func DumpRequest(req *http.Request)

func DumpResponse

func DumpResponse(resp *http.Response)

func GetFileHash

func GetFileHash(path string) (string, error)

GetFileHash returns the hex encoding of the sha-256 hash of the file at the specified path.

func NoCache

func NoCache(h http.Handler) http.Handler

NoCache disables browser caching.

func ParseFileSize

func ParseFileSize(s string) (int64, error)

ParseFileSize converts a string contains a positive integer and an optional KB/MB/GB unit to int64, or returns error.

func SanitizePathString

func SanitizePathString(s string) (output string)

func SetURLParam

func SetURLParam(in string, key string, value string) string

func TrimStringAsBytes

func TrimStringAsBytes(s string, maxLength int) string

func TrimStringAsRunes

func TrimStringAsRunes(numChars uint, s string, trimFront bool) string

Trim string to numChars: we only care about the number of runes (encoded characters of variable bytes) so we don't cut up multibyte characters

func ZipFiles

func ZipFiles(writer io.Writer, opts ZipOptions) (err error)

ZipFiles creates a zip archive per the options and writes to the writer.

Types

type ZipOptions

type ZipOptions struct {
	// The search patterns for the files / directories to be zipped, keyed to the
	// directory prefix used for storing the associated files in the ZIP,
	// The search pattern is described at the comments of path/filepath.Match.
	// As a special note, "**/*" doesn't match files not under a subdirectory.
	Globs map[string]string
	// The limit of total bytes of all the files in the archive.
	// All remaining files will be ignored if the limit would be hit.
	MaxBytes int64
}

ZipOptions is a set of options for ZipFiles.

Jump to

Keyboard shortcuts

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