Documentation
¶
Overview ¶
This succint etag middleware has been borrowed from:
https://github.com/wtg/shuttletracker/blob/cdd56dc4aeca922f333c913f09c1796851d6f677/api/etag.go
It's very well articulated too by the author on their blog:
https://sidney.kochman.org/2018/etag-middleware-go/
Package http provides an HTTP interface allowing HTTP clients to interact with otf.
Index ¶
- Constants
- Variables
- func Absolute(r *http.Request, path string) string
- func ExternalHost(r *http.Request) string
- func GetClientIP(r *http.Request) (string, error)
- func HeadersFromContext(ctx context.Context) (http.Header, error)
- func ParseURL(address string) (*url.URL, error)
- func SanitizeHostname(hostname string) (string, error)
- type Client
- type ClientConfig
- type Server
- type ServerConfig
Constants ¶
const ( APIBasePath = "/otfapi" APIPingEndpoint = "ping" DefaultURL = "https://localhost:8080" )
Variables ¶
var Encoder = schema.NewEncoder()
Encoder for encoding structs into queries: caches structs, and safe for sharing
var ErrParseURL = errors.New("url must begin with http:// or https:// and contain a hostname or ip address")
var InsecureTransport http.RoundTripper
Functions ¶
func Absolute ¶
Absolute returns an absolute URL for the given path. It uses the http request to determine the correct hostname and scheme to use. Handles situations where otf is sitting behind a reverse proxy, using the X-Forwarded-* headers the proxy sets.
func ExternalHost ¶
ExternalHost uses the incoming HTTP request to determine the host:port on which this server can be reached externally by clients and the internet.
func GetClientIP ¶
GetClientIP gets the client's IP address
func HeadersFromContext ¶ added in v0.2.0
func ParseURL ¶ added in v0.3.0
ParseURL parses address into a URL. The URL must be absolute with an http(s) scheme.
func SanitizeHostname ¶
SanitizeHostname ensures hostname is in the format <host>:<port>
Types ¶
type Client ¶
type Client struct {
Token string
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(config ClientConfig) (*Client, error)
func (*Client) Do ¶
Do sends an API request and returns the API response. The API response is JSONAPI decoded and the document's primary data is stored in the value pointed to by v, or returned as an error if an API error has occurred.
If v implements the io.Writer interface, the raw response body will be written to v, without attempting to first decode it.
The provided ctx must be non-nil. If it is canceled or times out, ctx.Err() will be returned.
func (*Client) NewRequest ¶
NewRequest creates an API request with proper headers and serialization.
A relative URL path can be provided, in which case it is resolved relative to the baseURL of the Client. Relative URL paths should always be specified without a preceding slash. Adding a preceding slash allows for ignoring the configured baseURL for non-standard endpoints.
If v is supplied, the value will be JSONAPI encoded and included as the request body. If the method is GET, the value will be parsed and added as query parameters.
type ClientConfig ¶ added in v0.5.1
type ClientConfig struct {
// The URL of the otf API.
URL string
// The base path on which the API is served.
BasePath string
// API token used to access the otf API.
Token string
// Headers that will be added to every request.
Headers http.Header
// Toggle retrying requests upon encountering transient errors.
RetryRequests bool
// Override default http transport
Transport http.RoundTripper
// Logger for logging an error upon retry
Logger logr.Logger
}
ClientConfig provides configuration details to the API client.
type Server ¶
type Server struct {
logr.Logger
ServerConfig
// contains filtered or unexported fields
}
Server is the http server for OTF
type ServerConfig ¶
type ServerConfig struct {
SSL bool
CertFile, KeyFile string
EnableRequestLogging bool
Handlers []internal.Handlers
// middleware to intercept requests, executed in the order given.
Middleware []mux.MiddlewareFunc
}
ServerConfig is the http server config