file

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// AllowedPunctuationInFilenames lists the punctuation characters that are tolerated
	// when converting URLs to filenames. This is initialised to a string appropriate for
	// the current OS.
	AllowedPunctuationInFilenames = nonWindowsPunct

	// FilenameTimestampFormat is the time format used for filenames containing a timestamp.
	FilenameTimestampFormat = "2006-01-02_15-04-05.000"
)
View Source
var PrettyIndent = ""

PrettyIndent sets the indentation used to pretty-print JSON and XML body files, when these are written (see WithHeadersAndBodies and LongBodyThreshold). When non-blank, PrettyIndent

View Source
var WriteJSONFile = func(out io.Writer, body []byte) error {
	if len(PrettyIndent) == 0 {
		return writePlainText(out, body)
	}

	var data interface{}
	err := json.NewDecoder(bytes.NewReader(body)).Decode(&data)
	if err != nil {
		return writePlainText(out, body)
	}

	var enc = json.NewEncoder(out)
	enc.SetIndent("", PrettyIndent)
	return enc.Encode(data)
}

WriteJSONFile is a function to write JSON files. If PrettyIndent is non-blank, the result is pretty-printed JSON; otherwise, it is verbatim.

An alternative function may be substituted if required.

View Source
var WriteXMLFile = func(out io.Writer, body []byte) error {
	if len(PrettyIndent) == 0 {
		return writePlainText(out, body)
	}

	xml := xmlfmt.FormatXML(string(body), "", PrettyIndent)
	if strings.HasPrefix(xml, xmlfmt.NL) {
		xml = xml[len(xmlfmt.NL):]
	}
	_, err := strings.NewReader(xml).WriteTo(out)
	return err
}

WriteXMLFile is a function to write XML files. If PrettyIndent is non-blank, the result is pretty-printed XML; otherwise, it is verbatim.

An alternative function may be substituted if required.

Functions

func FilenameTimestamp

func FilenameTimestamp(t time.Time) string

func Hostname

func Hostname(hdrs http.Header) string

Hostname gets the "Host" header and removes any disallowed punctuation characters.

func PrettyPrint

func PrettyPrint(extension string, out io.Writer, body []byte) error

PrettyPrint writes a body to a writer (usually a file). Pretty printing is implemented via transcoding for JSON and XML only. All other file times are written verbatim.

func UrlToFilename

func UrlToFilename(path string) string

Types

This section is empty.

Jump to

Keyboard shortcuts

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