faas

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

README

faas-go

OpenFaaS Go Helper functions

Documentation

Overview

Package faas is a OpenFaaS utility and helper function library designed to reduce boilerplate.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Background

func Background(fn func())

Background helper accepts an arbitrary function as a parameter.

func GetEnvOrError

func GetEnvOrError(env string) (string, error)

GetEnvOrError will return an error if the environment variable is not found.

func GetIpAddress

func GetIpAddress(r *http.Request) string

GetIpAddress retrieves the requests remote address.

func GetSecret

func GetSecret(secretName string) ([]byte, error)

GetSecret is a helper to retrieve kubernetes/openfaas secrets from the cluster.

func GetSecretString

func GetSecretString(secretName string) (string, error)

func ReadJSON

func ReadJSON(w http.ResponseWriter, r *http.Request, dst interface{}) error

ReadJSON is helper for trapping errors and return values for JSON related handlers

func ValidateCORS

func ValidateCORS(w http.ResponseWriter, r *http.Request, origins []string) error

ValidateCORS will check that the request is from a valid origin.

func ValidateMethod

func ValidateMethod(r *http.Request) error

ValidateMethod checks the http.Request is either GET or POST. Everything else returns an error.

func WriteJSON

func WriteJSON(w http.ResponseWriter, status int, data any, headers http.Header) error

WriteJSON will write a JSON response to the caller.

Types

type Error

type Error struct {
	Status string `json:"status"`
	Reason string `json:"reason,omitempty"`
	Code   int    `json:"code,omitempty"`
}

Error is the handler custom error struct for JSON responses

type Map

type Map map[string]any

Map is an interface for generating a custom untyped JSON object.

Jump to

Keyboard shortcuts

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