package
module
Version:
v0.4.2
Opens a new window with list of versions in this module.
Published: May 21, 2022
License: MIT
Opens a new window with license information.
Imports: 5
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
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
¶
Package functions provide a set of useful methods for google cloud functions
func Init(setup func() error)
Init should be called in the package init
Source Files
¶
Directories
¶
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 |
|
Package rate offers a rate limiter middleware |
tests
|
|
|
|
Package utils provides common functions
|
Package utils provides common functions |
Click to show internal directories.
Click to hide internal directories.