8000 GitHub - gpollatos/zeitx: utilities to quickly bootstrap an http, all-json service
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

gpollatos/zeitx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zeitx

utilities to quickly bootstrap and http all-json service

Usage

func main() {
  ...
  
  cfg, _ := zeitx.NewConfig(*configFile)
  srv := zeitx.NewHTTPServer(*cfg)
  srv.GETRoute("/", index)
  srv.ListenAndServe()
  
  ...
}

func index(w http.ResponseWriter, r *http.Request) {
  zeitx.OkJSON(w, r, &struct{ Version string }{Version: ver})
}

There are also json responses for errors as well as a handy querystring parameter pretty in order to easily inspect and debug:

-$ curl -i http://localhost:8090    
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Date: Thu, 22 Nov 2018 13:37:24 GMT
Content-Length: 19

{"Version":"3.0.0"}%
-$ curl -i http://localhost:8090\?pretty
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
X-Pretty-Print: 1
Date: Thu, 22 Nov 2018 13:37:28 GMT
Content-Length: 26

{
    "Version": "3.0.0"
}%                                                                        

See main.go for a working example.

About

utilities to quickly bootstrap an http, all-json service

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0