util

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HTTPWriteImage

func HTTPWriteImage(w http.ResponseWriter, img *image.Image)

HTTPWriteImage utility to write image to response writer

func Logger

func Logger(inner http.Handler, name string) http.Handler

// JSON responds to the request with the given code and payload func (app *app) JSON(w http.ResponseWriter, code int, payload interface{}) {

response, _ := json.Marshal(payload)
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.Header().Set("Access-Control-Allow-Origin", "*")
w.WriteHeader(code)
w.Write(response)

}

// JSON responds to the request with the given code and payload

func (app *app) ERROR(w http.ResponseWriter, code int, err error) {
	response := []byte(err.Error())
	w.Header().Set("Content-Type", "application/json; charset=utf-8")
	w.Header().Set("Access-Control-Allow-Origin", "*")
	w.WriteHeader(code)
	w.Write(response)
}

Logger function for http calls

func TimeTrack

func TimeTrack(start time.Time, name string)

TimeTrack ... see https://coderwall.com/p/cp5fya/measuring-execution-time-in-go

Types

type HTTPResponder

type HTTPResponder interface {
	JSON(w http.ResponseWriter, code int, payload interface{})
	ERROR(w http.ResponseWriter, code int, err error)
}

HTTPResponder serves method to respond to http calls

type Route

type Route struct {
	Pattern     string
	Method      string
	Name        string
	HandlerFunc http.Handler
}

Route ... contains data to declare a route

type Routes

type Routes []Route

Routes ... type to hold multiple routes

Jump to

Keyboard shortcuts

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