Documentation
¶
Index ¶
- func AtomicWriteFile(name string, data []byte, perm os.FileMode) error
- func ConvertToNativeLineEndings(b []byte) []byte
- func DetectMediaType(userGivenType string, filename string, getReader ReadCloserGetter) string
- func ExpandHome(path string) (string, error)
- func JsGetArray(js map[string]any, key string) []any
- func JsGetBool(js map[string]any, key string) *bool
- func JsGetMap(js map[string]any, key string) map[string]any
- func JsGetString(js map[string]any, key string) *string
- func NormalizeLineEndings(bytes []byte) []byte
- func ParseAsList(list, separator string, trim bool) []string
- func ReadFileLines(path string) ([]string, error)
- func ReadRequiredFile(name string) (string, []byte, error)
- func SanitizeName(name string) string
- func ToTrimmedLower(s string) string
- func WriteFileLines(lines []string, path string, mode os.FileMode) error
- type ReadCloserGetter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AtomicWriteFile ¶
AtomicWriteFile writes data to the named file quasi-atomically, creating it if necessary. On unix-like systems, the function uses github.com/google/renameio. On Windows, it has a simpler implementation using os.Rename(), which is believed to be atomic on NTFS, but there is no hard guarantee from Microsoft on that.
func ConvertToNativeLineEndings ¶
ConvertToNativeLineEndings converts all instances of '\n' to native line endings for the platform. Assumes that line endings are normalized, i.e. there are no '\r' or "\r\n" line endings in the data See NormalizeLineEndings
func DetectMediaType ¶
func DetectMediaType(userGivenType string, filename string, getReader ReadCloserGetter) string
DetectMediaType detects the media type of the file. The type provided by the user always takes precedence over automatic detection, unless it is empty. The type is detected by http.DetectContentType. If that returns the generic 'application/octet-stream', then the type is guessed from the filename extension. If all of the above fails, it returns 'application/octet-stream'
func ExpandHome ¶
ExpandHome expands ~ in path with user's home directory, but only if path begins with ~ or /~ Otherwise, returns path unchanged
func NormalizeLineEndings ¶
func ParseAsList ¶
func ReadFileLines ¶
ReadFileLines reads a whole file into memory and returns its lines.
func ReadRequiredFile ¶
ReadRequiredFile reads the file. Returns expanded absolute representation of the filename and file contents. Removes Byte-Order-Mark from the content
func SanitizeName ¶
func ToTrimmedLower ¶
Types ¶
type ReadCloserGetter ¶
type ReadCloserGetter func() (io.ReadCloser, error)
func ReadCloserGetterFromBytes ¶
func ReadCloserGetterFromBytes(raw []byte) ReadCloserGetter
func ReadCloserGetterFromFilename ¶
func ReadCloserGetterFromFilename(name string) ReadCloserGetter