Documentation
¶
Index ¶
- func ConvertURLsToStrings(urls []*url.URL) []string
- func GetServiceURL(serviceName, servicePort, serviceURL string) (string, error)
- func GetServiceURLOrDie(serviceName, servicePort, serviceURL string) string
- func IsHTTPURL(s string) bool
- func LogAndReturnError(handler string, statusCode int, err error, w http.ResponseWriter)
- func LogHandlerEntry(handler string, r *http.Request)
- func LogHandlerExit(handler string, statusCode int, status string, w http.ResponseWriter)
- func LogHandlerExitWithJSON(handler string, w http.ResponseWriter, v interface{}, statusCode int)
- func LogHandlerExitWithText(handler string, w http.ResponseWriter, v string, statusCode int)
- func LogHandlerExitWithYAML(handler string, w http.ResponseWriter, v interface{}, statusCode int)
- func LogHandlerText(handler string, v string)
- func MarshalAndWriteJSON(handler string, w http.ResponseWriter, v interface{}, statusCode int) []byte
- func MarshalAndWriteYAML(handler string, w http.ResponseWriter, v interface{}, statusCode int) []byte
- func NewTemplateFromArchive(name string, r io.Reader, importFileNames []string) (*common.Template, error)
- func NewTemplateFromFileNames(templateFileName string, importFileNames []string) (*common.Template, error)
- func NewTemplateFromReader(name string, r io.Reader, importFileNames []string) (*common.Template, error)
- func NewTemplateFromRootTemplate(templateFileName string) (*common.Template, error)
- func NewTemplateFromType(name, typeName string, properties map[string]interface{}) (*common.Template, error)
- func ParseKubernetesObject(object []byte) (*common.Resource, error)
- func TestHandlerWithURL(handler http.Handler, method, urlString string) (*httptest.ResponseRecorder, error)
- func ToJSONOrError(v interface{}) string
- func ToYAMLOrError(v interface{}) string
- func TrimURLScheme(URL string) string
- func WriteJSON(handler string, w http.ResponseWriter, j []byte, status int)
- func WriteResponse(handler string, w http.ResponseWriter, v []byte, ct string, status int)
- func WriteYAML(handler string, w http.ResponseWriter, y []byte, status int)
- type HTTPClient
- type HTTPDoer
- type HandlerTester
- type Kubernetes
- type KubernetesConfig
- type KubernetesKubectl
- type KubernetesObject
- type KubernetesSecret
- type ServerTester
- type Sleeper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertURLsToStrings ¶
ConvertURLsToStrings converts a slice of *url.URL to a slice of string.
func GetServiceURL ¶
GetServiceURL takes a service name, a service port, and a default service URL, and returns a URL for accessing the service. It first looks for an environment variable set by Kubernetes by transposing the service name. If it can't find one, it looks up the service name in DNS. If that doesn't work, it returns the default service URL. If that's empty, it returns an HTTP localhost URL for the service port. If service port is empty, it panics.
func GetServiceURLOrDie ¶
GetServiceURLOrDie calls GetServiceURL and exits if it returns an error.
func LogAndReturnError ¶
func LogAndReturnError(handler string, statusCode int, err error, w http.ResponseWriter)
LogAndReturnError logs the given error and status to stderr, and then returns them as the HTTP response.
func LogHandlerEntry ¶
LogHandlerEntry logs the start of the given handler handling the given request.
func LogHandlerExit ¶
func LogHandlerExit(handler string, statusCode int, status string, w http.ResponseWriter)
LogHandlerExit logs the response from the given handler with the given results.
func LogHandlerExitWithJSON ¶
func LogHandlerExitWithJSON(handler string, w http.ResponseWriter, v interface{}, statusCode int)
LogHandlerExitWithJSON marshals the given object as JSON, writes it to the response body, returns the given status, and then logs the response.
func LogHandlerExitWithText ¶
func LogHandlerExitWithText(handler string, w http.ResponseWriter, v string, statusCode int)
LogHandlerExitWithText converts the given string to []byte, writes it to the response body, returns the given status, and then logs the response
func LogHandlerExitWithYAML ¶
func LogHandlerExitWithYAML(handler string, w http.ResponseWriter, v interface{}, statusCode int)
LogHandlerExitWithYAML marshals the given object as YAML, writes it to the response body, returns the given status, and then logs the response.
func LogHandlerText ¶
LogHandlerText logs a line of text for a handler.
func MarshalAndWriteJSON ¶
func MarshalAndWriteJSON(handler string, w http.ResponseWriter, v interface{}, statusCode int) []byte
MarshalAndWriteJSON marshals the given object as JSON, writes it to the response body, and then returns the given status.
func MarshalAndWriteYAML ¶
func MarshalAndWriteYAML(handler string, w http.ResponseWriter, v interface{}, statusCode int) []byte
MarshalAndWriteYAML marshals the given object as YAML, writes it to the response body, and then returns the given status.
func NewTemplateFromArchive ¶
func NewTemplateFromArchive(name string, r io.Reader, importFileNames []string) (*common.Template, error)
NewTemplateFromArchive creates and returns a new template whose content and imported files are read from the supplied archive.
func NewTemplateFromFileNames ¶
func NewTemplateFromFileNames( templateFileName string, importFileNames []string, ) (*common.Template, error)
NewTemplateFromFileNames creates and returns a new template whose content and imported files are read from the supplied file names.
func NewTemplateFromReader ¶
func NewTemplateFromReader(name string, r io.Reader, importFileNames []string) (*common.Template, error)
NewTemplateFromReader creates and returns a new template whose content is read from the supplied reader.
func NewTemplateFromRootTemplate ¶
NewTemplateFromRootTemplate creates and returns a new template whose content and imported files are constructed from reading the root template, parsing out the imports section and reading the imports from there
func NewTemplateFromType ¶
func NewTemplateFromType(name, typeName string, properties map[string]interface{}) (*common.Template, error)
NewTemplateFromType creates and returns a new template whose content is a YAML marshaled resource assembled from the supplied arguments.
func ParseKubernetesObject ¶
ParseKubernetesObject parses a Kubernetes API object in YAML format.
func TestHandlerWithURL ¶
func TestHandlerWithURL(handler http.Handler, method, urlString string) (*httptest.ResponseRecorder, error)
TestHandlerWithURL creates a HandlerTester with the given handler, and tests it with the given HTTP method and URL string using HandlerTester.TestWithURL.
func ToJSONOrError ¶
func ToJSONOrError(v interface{}) string
ToJSONOrError marshals the given object to JSON and returns either the resulting YAML or an error message. Useful when marshaling an object for a log entry.
func ToYAMLOrError ¶
func ToYAMLOrError(v interface{}) string
ToYAMLOrError marshals the given object to YAML and returns either the resulting YAML or an error message. Useful when marshaling an object for a log entry.
func TrimURLScheme ¶
TrimURLScheme removes the scheme, if any, from an URL.
func WriteJSON ¶
func WriteJSON(handler string, w http.ResponseWriter, j []byte, status int)
WriteJSON writes the given bytes to the response body, sets the content type to "application/json; charset=UTF-8", and then returns the given status.
func WriteResponse ¶
WriteResponse writes the given bytes to the response body, sets the content type to the given value, and then returns the given status.
Types ¶
type HTTPClient ¶
HTTPClient is a higher level HTTP client which takes a URL and returns the response body as a string, along with the resulting status code and any errors.
func DefaultHTTPClient ¶
func DefaultHTTPClient() HTTPClient
DefaultHTTPClient returns a default http client.
func NewHTTPClient ¶
func NewHTTPClient(retries uint, c HTTPDoer, s Sleeper) HTTPClient
NewHTTPClient returns a new HTTPClient.
type HTTPDoer ¶
HTTPDoer is an interface for something that can 'Do' an http.Request and return an http.Response and error.
type HandlerTester ¶
type HandlerTester func(method, path, ctype string, reader io.Reader) (*httptest.ResponseRecorder, error)
A HandlerTester is a function that takes an HTTP method, an URL path, and a reader for a request body, creates a request from them, and serves it to the handler to which it was bound and returns a response recorder describing the outcome.
func NewHandlerTester ¶
func NewHandlerTester(handler http.Handler) HandlerTester
NewHandlerTester creates and returns a new HandlerTester for an http.Handler.
func (HandlerTester) TestWithURL ¶
func (h HandlerTester) TestWithURL(method, urlString string) (*httptest.ResponseRecorder, error)
TestWithURL invokes a HandlerTester with the given HTTP method, an URL path parsed from the given URL string, and a string reader on the query parameters parsed from the given URL string.
type Kubernetes ¶
type Kubernetes interface {
Get(name string, resourceType string) (string, error)
Create(resource string) (string, error)
Delete(resource string) (string, error)
Replace(resource string) (string, error)
}
Kubernetes defines the interface for talking to Kubernetes. Currently the only implementation is through kubectl, but eventually this could be done via direct API calls.
func NewKubernetesKubectl ¶
func NewKubernetesKubectl(config *KubernetesConfig) Kubernetes
NewKubernetesKubectl creates a new Kubernetes kubectl wrapper.
type KubernetesConfig ¶
type KubernetesConfig struct {
KubePath string // The path to kubectl binary
KubeService string // DNS name of the kubernetes service
KubeServer string // The IP address and optional port of the kubernetes master
KubeInsecure bool // Do not check the server's certificate for validity
KubeConfig string // Path to a kubeconfig file
KubeCertAuth string // Path to a file for the certificate authority
KubeClientCert string // Path to a client certificate file
KubeClientKey string // Path to a client key file
KubeToken string // A service account token
KubeUsername string // The username to use for basic auth
KubePassword string // The password to use for basic auth
}
KubernetesConfig defines the configuration options for talking to Kubernetes master
type KubernetesKubectl ¶
type KubernetesKubectl struct {
KubePath string
// Base level arguments to kubectl. User commands/arguments get appended to this.
Arguments []string
}
KubernetesKubectl implements the interface for talking to Kubernetes by wrapping calls via kubectl.
func (*KubernetesKubectl) Create ¶
func (k *KubernetesKubectl) Create(resource string) (string, error)
Create runs a kubectl create command for a given resource.
func (*KubernetesKubectl) Delete ¶
func (k *KubernetesKubectl) Delete(resource string) (string, error)
Delete runs a kubectl delete command for a given resource.
type KubernetesObject ¶
type KubernetesObject struct {
Kind string `json:"kind"`
APIVersion string `json:"apiVersion"`
Metadata map[string]interface{} `json:"metadata"`
Spec map[string]interface{} `json:"spec"`
}
KubernetesObject represents a native 'bare' Kubernetes object.
type KubernetesSecret ¶
type KubernetesSecret struct {
Kind string `json:"kind"`
APIVersion string `json:"apiVersion"`
Metadata map[string]string `json:"metadata"`
Data map[string]string `json:"data,omitempty"`
}
KubernetesSecret represents a Kubernetes secret
type ServerTester ¶
A ServerTester is a function that takes an HTTP method, an URL path, and a reader for a request body, creates a request from them, and serves it to a test server using the handler to which it was bound and returns the response.
func NewServerTester ¶
func NewServerTester(handler http.Handler) ServerTester
NewServerTester creates and returns a new NewServerTester for an http.Handler.