rpc

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2020 License: GPL-2.0, GPL-3.0 Imports: 11 Imported by: 21

Documentation

Index

Constants

View Source
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
	StatusUnauthorized        = http.StatusUnauthorized        //  401 RFC 7235, 3.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
	StatusServiceUnavailable  = http.StatusServiceUnavailable  //  503 RFC 7231, 6.6.4
)

define these here since we only have stuff that's needed / supported

Variables

View Source
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

func CheckHTTPSRedirect(urlString string) (bool, error)

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 Err

func Err(w http.ResponseWriter, err error, status int, msgs ...string) bool

Err prints an error and returns to the caller

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

func GetRequest(url string) ([]byte, error)

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

func HttpsGet(client *http.Client, url string) ([]byte, error)

HttpsGet is a function that should only be used on localhost with a client configured to accept a user generated cert

func HttpsPost

func HttpsPost(client *http.Client, url string, postdata url.Values) ([]byte, error)

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 PostForm

func PostForm(body string, postdata url.Values) ([]byte, error)

PostForm is a handler that makes it easy to send out POST form requests

func PostRequest

func PostRequest(body string, payload io.Reader) ([]byte, error)

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

func PutRequest(body string, payload io.Reader) ([]byte, error)

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

func SetupLocalHttpsClient(path string, timeout time.Duration) *http.Client

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

type StatusResponse struct {
	Code    int
	Status  string
	Message string
}

StatusResponse defines a generic status response structure

Jump to

Keyboard shortcuts

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