functions

package module
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: May 21, 2022 License: MIT Imports: 5 Imported by: 0

README

Functions

A simple utility to make writing cloud functions easier.

Usage

The main advantages are:

  • avoid boilerplate code to write JSON responses
  • set up log level using a LOG_LEVEL env var
  • set up sentry using SENTRY_DNS env var
  • handle HTTPErrors automatically
var someVariable string

// Setup code
func init() {
    functions.Init(func() (err error) {
        someVariable = "world"
        return nil
    }
}
// Execution
func call(w http.ResponseWriter, r *http.Request) error {
	if r.Method != "GET" {
		w.WriteHeader(http.StatusMethodNotAllowed)
		return nil
    }

    hello := map[string]string {
        "hello": someVariable,
    }

	return functions.JSON(w, 200, hello)
}

// HTTP is the actual cloud function
var HTTP = functions.MakeFunction(errors.DefaultTranslator, call)

Documentation

Overview

Package functions provide a set of useful methods for google cloud functions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(setup func() error)

Init should be called in the package init

Types

This section is empty.

Directories

Path Synopsis
Package router routes requests
Package router routes requests
middleware
Package middleware has a set of commonly used middlewares
Package middleware has a set of commonly used middlewares
middleware/rate
Package rate offers a rate limiter middleware
Package rate offers a rate limiter middleware
tests
Package utils provides common functions
Package utils provides common functions

Jump to

Keyboard shortcuts

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