New port: devel/go-rest-json:

Go-Json-Rest is a thin layer on top of net/http that helps building RESTful
JSON APIs easily. It provides fast URL routing using a Trie based
implementation, and helpers to deal with JSON requests and responses. It is
not a high-level REST framework that transparently maps HTTP requests
to procedure calls, on the opposite, you constantly have access to the
underlying net/http objects.

WWW: https://github.com/ant0ine/go-json-rest/
This commit is contained in:
Ryan Steinmetz 2014-02-26 17:15:02 +00:00
parent 2609bd6484
commit 78fc6dd36e
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=346216
6 changed files with 103 additions and 0 deletions

View file

@ -589,6 +589,7 @@
SUBDIR += gnulibiberty
SUBDIR += gnustep
SUBDIR += gnustep-make
SUBDIR += go-json-rest
SUBDIR += go-pretty
SUBDIR += go-sql-driver
SUBDIR += gob2

View file

@ -0,0 +1,18 @@
# Created by: Ryan Steinmetz <zi@FreeBSD.org>
# $FreeBSD$
PORTNAME= go-json-rest
PORTVERSION= 20140226
CATEGORIES= devel
MASTER_SITES= LOCAL/zi/ \
http://mirrors.rit.edu/zi/
MAINTAINER= lattera@gmail.com
COMMENT= Quick and easy way to setup a RESTful JSON API
GO_PKGNAME= github.com/ant0ine/go-json-rest
WRKSRC= ${WRKDIR}/${PORTNAME}-master
.include <bsd.port.pre.mk>
.include "${PORTSDIR}/lang/go/files/bsd.go.mk"
.include <bsd.port.post.mk>

View file

@ -0,0 +1,2 @@
SHA256 (go-json-rest-20140226.tar.gz) = b2d04af83c7c6c6819e5d6518b1a8c4b3a25c744ee917194ba4e7255f424e5f0
SIZE (go-json-rest-20140226.tar.gz) = 16373

View file

@ -0,0 +1,39 @@
--- ./request.go.orig 2014-02-25 00:55:56.000000000 -0500
+++ ./request.go 2014-02-26 11:51:45.000000000 -0500
@@ -15,19 +15,34 @@
PathParams map[string]string
}
+func CToGoString(c []byte) string {
+ n := -1
+ for i, b := range c {
+ if b == 0 {
+ break
+ }
+ n = i
+ }
+ return string(c[:n+1])
+}
+
// Provide a convenient access to the PathParams map
func (self *Request) PathParam(name string) string {
return self.PathParams[name]
}
// Read the request body and decode the JSON using json.Unmarshal
-func (self *Request) DecodeJsonPayload(v interface{}) error {
+func (self *Request) DecodeJsonPayload(v interface{}, decodeBody bool) error {
content, err := ioutil.ReadAll(self.Body)
self.Body.Close()
if err != nil {
return err
}
- err = json.Unmarshal(content, v)
+ contentstr := ""
+ if decodeBody == true {
+ contentstr, _ = url.QueryUnescape(CToGoString(content))
+ }
+ err = json.Unmarshal([]byte(contentstr), v)
if err != nil {
return err
}

View file

@ -0,0 +1,8 @@
Go-Json-Rest is a thin layer on top of net/http that helps building RESTful
JSON APIs easily. It provides fast URL routing using a Trie based
implementation, and helpers to deal with JSON requests and responses. It is
not a high-level REST framework that transparently maps HTTP requests
to procedure calls, on the opposite, you constantly have access to the
underlying net/http objects.
WWW: https://github.com/ant0ine/go-json-rest/

View file

@ -0,0 +1,35 @@
@comment $FreeBSD$
%%GO_LIBDIR%%/github.com/ant0ine/go-json-rest.a
%%GO_SRCDIR%%/%%GO_PKGNAME%%/LICENSE
%%GO_SRCDIR%%/%%GO_PKGNAME%%/README.md
%%GO_SRCDIR%%/%%GO_PKGNAME%%/env.go
%%GO_SRCDIR%%/%%GO_PKGNAME%%/gzip.go
%%GO_SRCDIR%%/%%GO_PKGNAME%%/gzip_test.go
%%GO_SRCDIR%%/%%GO_PKGNAME%%/handler.go
%%GO_SRCDIR%%/%%GO_PKGNAME%%/handler_test.go
%%GO_SRCDIR%%/%%GO_PKGNAME%%/log.go
%%GO_SRCDIR%%/%%GO_PKGNAME%%/recorder.go
%%GO_SRCDIR%%/%%GO_PKGNAME%%/request.go
%%GO_SRCDIR%%/%%GO_PKGNAME%%/request.go.orig
%%GO_SRCDIR%%/%%GO_PKGNAME%%/request_test.go
%%GO_SRCDIR%%/%%GO_PKGNAME%%/response.go
%%GO_SRCDIR%%/%%GO_PKGNAME%%/router.go
%%GO_SRCDIR%%/%%GO_PKGNAME%%/router_benchmark_test.go
%%GO_SRCDIR%%/%%GO_PKGNAME%%/router_test.go
%%GO_SRCDIR%%/%%GO_PKGNAME%%/status.go
%%GO_SRCDIR%%/%%GO_PKGNAME%%/status_test.go
%%GO_SRCDIR%%/%%GO_PKGNAME%%/test/util.go
%%GO_SRCDIR%%/%%GO_PKGNAME%%/timer.go
%%GO_SRCDIR%%/%%GO_PKGNAME%%/trie/impl.go
%%GO_SRCDIR%%/%%GO_PKGNAME%%/trie/impl_test.go
@dirrm %%GO_SRCDIR%%/%%GO_PKGNAME%%/test
@dirrm %%GO_SRCDIR%%/%%GO_PKGNAME%%/trie
@dirrmtry %%GO_SRCDIR%%/%%GO_PKGNAME%%
@dirrmtry %%GO_SRCDIR%%/github.com/ant0ine
@dirrmtry %%GO_SRCDIR%%/github.com
@dirrmtry %%GO_LIBDIR%%/github.com/ant0ine
@dirrmtry %%GO_LIBDIR%%/github.com
@dirrmtry %%GO_LIBDIR%%
@dirrmtry %%GO_SRCDIR%%
@dirrmtry share/go/pkg
@dirrmtry share/go