util

package
v4.1.12+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExternalIP

func ExternalIP() (string, error)

returns the ipv4 address of the current machine

func IsNotFound

func IsNotFound(err error) bool

tests if an error was a WebError with http.NotFound OR a mongo error string of not found

func RequiredValue

func RequiredValue(value string, envname string, defaultvalue string) (s string)

returns either the value passed in, the value of the environment string specified, or the default. If the result of all of that is blank, panics.

func WriteError

func WriteError(rw http.ResponseWriter, code string, err error)

WriteError writes any kind of error If it's a Web error, it defers to that and ignores the code passed in. If it's any other kind of error, it builds a new WebError for an InternalServerError (500) with the given code.

If you're calling this, it's because you expect that the call wasn't going to fail unless there was some system problem.

func WriteJSON

func WriteJSON(rw http.ResponseWriter, j interface{})

func WriteJSONPretty

func WriteJSONPretty(rw http.ResponseWriter, j interface{})

func WriteNewWebError

func WriteNewWebError(rw http.ResponseWriter, code int, errorcode string, msg string)

func WriteWebError

func WriteWebError(rw http.ResponseWriter, we *WebError)

Types

type WebError

type WebError struct {
	Code      int
	ErrorCode string // should be unique across all our packages
	Msg       string
	Detail    map[string]string
}

func NewWebError

func NewWebError(code int, errorcode string, msg string) *WebError

func (*WebError) Add

func (we *WebError) Add(k, v string) *WebError

func (WebError) Error

func (we WebError) Error() string

func (WebError) GetJSON

func (we WebError) GetJSON(formatted bool) string

DEPRECATED -- after the next deploy of tagserver, this function will no longer be called anywhere and should be deleted.

func (WebError) MarshalJSON

func (we WebError) MarshalJSON() ([]byte, error)

Jump to

Keyboard shortcuts

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