util

package module
v0.0.0-...-95bffaa Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2015 License: MIT Imports: 9 Imported by: 1

README

util

Some utility functions I've found useful for Go programming.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExpandPath

func ExpandPath(elem ...string) (string, error)

ExpandPath: Expand the path to its full path.

func FileExists

func FileExists(elem ...string) bool

fileExists: Return true if the path exists. Arguments are joined with filepath.Join to construct the full path.

func HttpToHttps

func HttpToHttps()

HttpToHttps: Accept connections on port 80 and forward to the same host using https. This will run in an infinite loop, or panic if it can't listen.

func JsonMarshal

func JsonMarshal(path string, v interface{}) error

JsonMarshal: attempt to write out the given object as json into the given file. This function won't overwrite an existing file.

func JsonUnmarshal

func JsonUnmarshal(path string, v interface{}) error

JsonUnmarshal: attempt to unmarshal the json file into the given object.

func ListenAndServeTLSWithLogging

func ListenAndServeTLSWithLogging(
	addr string, handler http.Handler, crtPath, keyPath string) error

ListenAndServeTLSWithLogging: Like ListenAndServeWithLogging, but with encryption.

func ListenAndServeWithLogging

func ListenAndServeWithLogging(addr string, handler http.Handler) error

ListenAndServeWithLogging: A wrapper for the standard library's http.ListenAndServe function, logging requests using the standard logger. Uses http.DefaultServeMux.

Types

type PrefixLogger

type PrefixLogger struct {
	// contains filtered or unexported fields
}

func NewPrefixLogger

func NewPrefixLogger(prefix string) *PrefixLogger

func (*PrefixLogger) Err

func (pl *PrefixLogger) Err(err error, format string, v ...interface{})

Err: Prints the error with the given message. Appends a colon and a newline to the message.

func (*PrefixLogger) Msg

func (pl *PrefixLogger) Msg(format string, v ...interface{})

Msg: Just link Printf, but adds an additional newline to the end of the message.

Jump to

Keyboard shortcuts

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