Back to godoc.org
zgo.at/zhttp

package zhttp

v0.0.0 (d637cf7)
Latest Go to latest
Published: 1 day ago | License: MIT | Module: zgo.at/zhttp

Module

zgo.at/zhttp

README

This project is considered experimental Build Status codecov GoDoc

Martin’s HTTP package: It’s not a “framework”, but just a collection of functions for building HTTP services.

Convention over configuration. Honestly, I’m not sure how useful this will be for other people at this stage (or ever), but it’s pretty useful for me.


zhttp.Wrap() allows returning errors from HTTP endpoints:

http.HandleFunc("/bar", zhttp.Wrap(func(w http.ResponseWriter, r *http.Request) error {
  d, err := getData()
  if err != nil {
      return err
  }

  return zhttp.String("Hello, %s", d)
}))

It’s just more convenient than http.Error(...) followed by a return. The ErrFunc() will be used to report returned errors (you can override it if you need to).

Return helpers:

  • zhttp.String()
  • zhttp.JSON()
  • zhttp.Template()
  • zhttp.SeeOther()

zhttp.Decode()scans forms, JSON body, or URL query parameters in to a struct. It’s just a convencience wrapper around formam.


zhttp.HostRoute() routes request to chi routers based on the Host header.

Source: zgo.at/zhttp@v0.0.0-20200602011947-d637cf767b75/README.markdown