Documentation ¶
Index ¶
- Constants
- Variables
- func CheckGet(w http.ResponseWriter, r *http.Request) error
- func CheckHTTPSRedirect(urlString string) (bool, error)
- func CheckOrigin(w http.ResponseWriter, r *http.Request) error
- func CheckPost(w http.ResponseWriter, r *http.Request) error
- func CheckPut(w http.ResponseWriter, r *http.Request) error
- func Err(w http.ResponseWriter, err error, status int, msgs ...string) bool
- func GetAndSendByte(w http.ResponseWriter, body string)
- func GetAndSendJson(w http.ResponseWriter, body string, x interface{})
- func GetRequest(url string) ([]byte, error)
- func HTTPSRedirect(w http.ResponseWriter, r *http.Request, origin string)
- func HttpsGet(client *http.Client, url string) ([]byte, error)
- func HttpsPost(client *http.Client, url string, postdata url.Values) ([]byte, error)
- func MarshalSend(w http.ResponseWriter, x interface{})
- func PostForm(body string, postdata url.Values) ([]byte, error)
- func PostRequest(body string, payload io.Reader) ([]byte, error)
- func PutAndSend(w http.ResponseWriter, body string, payload io.Reader)
- func PutRequest(body string, payload io.Reader) ([]byte, error)
- func ResponseHandler(w http.ResponseWriter, status int, messages ...string)
- func SetConsts(timeout int)
- func SetupBasicHandlers()
- func SetupDefaultHandler()
- func SetupLocalHttpsClient(path string, timeout time.Duration) *http.Client
- func SetupPingHandler()
- func WriteToHandler(w http.ResponseWriter, jsonString []byte)
- type StatusResponse
Constants ¶
const ( StatusOK = http.StatusOK // 200 RFC 7231, 6.3.1 StatusCreated = http.StatusCreated // 201 RFC 7231, 6.3.2 StatusMovedPermanently = http.StatusMovedPermanently // 301 RFC 7231, 6.4.2 StatusBadRequest = http.StatusBadRequest // 400 RFC 7231, 6.5.1 StatusPaymentRequired = http.StatusPaymentRequired // 402 RFC 7231, 6.5.2 StatusNotFound = http.StatusNotFound // 404 RFC 7231, 6.5.4 StatusInternalServerError = http.StatusInternalServerError // 500 RFC 7231, 6.6.1 StatusBadGateway = http.StatusBadGateway // 502 RFC 7231, 6.6.3 StatusLocked = http.StatusLocked // 423 RFC 4918, 11.3 StatusTooManyRequests = http.StatusTooManyRequests // 429 RFC 6585, 4 StatusGatewayTimeout = http.StatusGatewayTimeout // 504 RFC 7231, 6.6.5 StatusNotAcceptable = http.StatusNotAcceptable // 406 RFC 7231, 6.5.6 )
define these here since we only have stuff that's needed / supported
Variables ¶
var TimeoutVal = 5 * time.Second
TimeoutVal is the timeout associated with a single call
Functions ¶
func CheckGet ¶
func CheckGet(w http.ResponseWriter, r *http.Request) error
CheckGet checks if the incoming request is a GET request
func CheckHTTPSRedirect ¶
CheckHTTPSRedirect checks if HTTP requests are redirected to HTTPS on the same host
func CheckOrigin ¶
func CheckOrigin(w http.ResponseWriter, r *http.Request) error
CheckOrigin checks if the origin of the incoming request is localhost
func CheckPost ¶
func CheckPost(w http.ResponseWriter, r *http.Request) error
CheckPost checks whether the incoming request is a POST request
func CheckPut ¶
func CheckPut(w http.ResponseWriter, r *http.Request) error
CheckPut checks whether the incoming request is a PUT request
func GetAndSendByte ¶
func GetAndSendByte(w http.ResponseWriter, body string)
GetAndSendByte is a handler that makes a get request and returns byte data. This is used in cases for which we don't know the format of the returned data, so we can't parse it
func GetAndSendJson ¶
func GetAndSendJson(w http.ResponseWriter, body string, x interface{})
GetAndSendJson is a handler that makes a get request and returns json data
func GetRequest ¶
GetRequest is a handler that makes it easy to send out GET requests
func HTTPSRedirect ¶
func HTTPSRedirect(w http.ResponseWriter, r *http.Request, origin string)
HTTPSRedirect redirects servers to use https instead of http
func HttpsGet ¶
HttpsGet is a function that should only be used on localhost with a client configured to accept a user generated cert
func HttpsPost ¶
HttpsPost is a function that should only be used on localhost with a client configured to accept a user generated cert
func MarshalSend ¶
func MarshalSend(w http.ResponseWriter, x interface{})
MarshalSend marshals and writes a json string
func PostRequest ¶
PostRequest is a handler that makes it easy to send out POST requests
func PutAndSend ¶
func PutAndSend(w http.ResponseWriter, body string, payload io.Reader)
PutAndSend is a handler that PUTs data and returns the response
func PutRequest ¶
PutRequest is a handler that makes it easy to send out PUT requests
func ResponseHandler ¶
func ResponseHandler(w http.ResponseWriter, status int, messages ...string)
ResponseHandler is the default response handler that sends out response codes on successful completion of certain calls
func SetConsts ¶
func SetConsts(timeout int)
SetConsts is used to set the timeout interval for requests made
func SetupBasicHandlers ¶
func SetupBasicHandlers()
SetupBasicHandlers sets up two handler functions that serve ping and default response at /
func SetupDefaultHandler ¶
func SetupDefaultHandler()
SetupDefaultHandler sets up the default handler (ie returns 404 for invalid routes)
func SetupLocalHttpsClient ¶
SetupLocalHttpsClient can be used to setup a local client configured to accept a user generated cert
func SetupPingHandler ¶
func SetupPingHandler()
SetupPingHandler is a ping route for remote callers to check if the platform is up
func WriteToHandler ¶
func WriteToHandler(w http.ResponseWriter, jsonString []byte)
WriteToHandler returns a reply to the passed writer
Types ¶
type StatusResponse ¶
StatusResponse defines a generic status response structure