Updated: build status badge, the go get installation instruction to account for the repo move, readme examples use ID instead of Id (so that they would be linter compliant if copy/pasted). shwoodard/jsonapi => google/jsonapi (#41)

This commit is contained in:
Aren Patel 2016-07-22 18:31:33 -07:00 committed by GitHub
parent b4fad2f2e6
commit dd46e31eb5
5 changed files with 29 additions and 29 deletions

View File

@ -1,16 +1,16 @@
# jsonapi
[![Build Status](https://travis-ci.org/shwoodard/jsonapi.svg?branch=master)](https://travis-ci.org/shwoodard/jsonapi)
[![Build Status](https://travis-ci.org/google/jsonapi.svg?branch=master)](https://travis-ci.org/google/jsonapi)
A serailizer/deserializer for json payloads that comply to the
[JSON API - jsonapi.org](http://jsonapi.org) spec in go.
Also visit, [Godoc](http://godoc.org/github.com/shwoodard/jsonapi).
Also visit, [Godoc](http://godoc.org/github.com/google/jsonapi).
## Installation
```
go get -u github.com/shwoodard/jsonapi
go get -u github.com/google/jsonapi
```
Or, see [Alternative Installation](#alternative-installation).
@ -42,7 +42,7 @@ that look similar to these:
```go
type Blog struct {
Id int `json:"id"`
ID int `json:"id"`
Title string `json:"title"`
Posts []*Post `json:"posts"`
CurrentPost *Post `json:"current_post"`
@ -52,8 +52,8 @@ type Blog struct {
}
type Post struct {
Id int `json:"id"`
BlogId int `json:"blog_id"`
ID int `json:"id"`
BlogID int `json:"blog_id"`
Title string `json:"title"`
Body string `json:"body"`
Comments []*Comment `json:"comments"`
@ -61,7 +61,7 @@ type Post struct {
type Comment struct {
Id int `json:"id"`
PostId int `json:"post_id"`
PostID int `json:"post_id"`
Body string `json:"body"`
Likes uint `json:"likes_count,omitempty"`
}
@ -74,7 +74,7 @@ all of your data easily.
## Example App
[examples/app.go](https://github.com/shwoodard/jsonapi/blob/master/examples/app.go)
[examples/app.go](https://github.com/google/jsonapi/blob/master/examples/app.go)
This runnable file demonstrates the implementation of a create, a show,
and a list [http.Handler](http://golang.org/pkg/net/http#Handler). It
@ -89,10 +89,10 @@ To run,
* Create the following directories or similar: `~/go`
* `cd` there
* Set `GOPATH` to `PWD` in your shell session, `export GOPATH=$PWD`
* `go get github.com/shwoodard/jsonapi`. (Append `-u` after `get` if you
* `go get github.com/google/jsonapi`. (Append `-u` after `get` if you
are updating.)
* `go run src/github.com/shwoodard/jsonapi/examples/app.go` or `cd
src/github.com/shwoodard/jsonapi/examples && go run app.go`
* `go run src/github.com/google/jsonapi/examples/app.go` or `cd
src/github.com/google/jsonapi/examples && go run app.go`
## `jsonapi` Tag Reference
@ -107,26 +107,26 @@ using JSON API tags:
```go
type Blog struct {
Id int `jsonapi:"primary,blogs"`
ID int `jsonapi:"primary,blogs"`
Title string `jsonapi:"attr,title"`
Posts []*Post `jsonapi:"relation,posts"`
CurrentPost *Post `jsonapi:"relation,current_post"`
CurrentPostId int `jsonapi:"attr,current_post_id"`
CurrentPostID int `jsonapi:"attr,current_post_id"`
CreatedAt time.Time `jsonapi:"attr,created_at"`
ViewCount int `jsonapi:"attr,view_count"`
}
type Post struct {
Id int `jsonapi:"primary,posts"`
BlogId int `jsonapi:"attr,blog_id"`
ID int `jsonapi:"primary,posts"`
BlogID int `jsonapi:"attr,blog_id"`
Title string `jsonapi:"attr,title"`
Body string `jsonapi:"attr,body"`
Comments []*Comment `jsonapi:"relation,comments"`
}
type Comment struct {
Id int `jsonapi:"primary,comments"`
PostId int `jsonapi:"attr,post_id"`
ID int `jsonapi:"primary,comments"`
PostID int `jsonapi:"attr,post_id"`
Body string `jsonapi:"attr,body"`
Likes uint `jsonapi:"attr,likes-count,omitempty"`
}
@ -186,7 +186,7 @@ about the rest?
### Create Record Example
You can Unmarshal a JSON API payload using
[jsonapi.UnmarshalPayload](http://godoc.org/github.com/shwoodard/jsonapi#UnmarshalPayload).
[jsonapi.UnmarshalPayload](http://godoc.org/github.com/google/jsonapi#UnmarshalPayload).
It reads from an [io.Reader](https://golang.org/pkg/io/#Reader)
containing a JSON API payload for one record (but can have related
records). Then, it materializes a struct that you created and passed in
@ -195,7 +195,7 @@ the top level, in request payloads at the moment. Bulk creates and
updates are not supported yet.
After saving your record, you can use,
[MarshalOnePayload](http://godoc.org/github.com/shwoodard/jsonapi#MarshalOnePayload),
[MarshalOnePayload](http://godoc.org/github.com/google/jsonapi#MarshalOnePayload),
to write the JSON API response to an
[io.Writer](https://golang.org/pkg/io/#Writer).
@ -205,7 +205,7 @@ to write the JSON API response to an
UnmarshalPayload(in io.Reader, model interface{})
```
Visit [godoc](http://godoc.org/github.com/shwoodard/jsonapi#UnmarshalPayload)
Visit [godoc](http://godoc.org/github.com/google/jsonapi#UnmarshalPayload)
#### `MarshalOnePayload`
@ -213,7 +213,7 @@ Visit [godoc](http://godoc.org/github.com/shwoodard/jsonapi#UnmarshalPayload)
MarshalOnePayload(w io.Writer, model interface{}) error
```
Visit [godoc](http://godoc.org/github.com/shwoodard/jsonapi#MarshalOnePayload)
Visit [godoc](http://godoc.org/github.com/google/jsonapi#MarshalOnePayload)
Writes a JSON API response, with related records sideloaded, into an
`included` array. This method encodes a response for a single record
@ -250,7 +250,7 @@ func CreateBlog(w http.ResponseWriter, r *http.Request) {
MarshalManyPayload(w io.Writer, models []interface{}) error
```
Visit [godoc](http://godoc.org/github.com/shwoodard/jsonapi#MarshalManyPayload)
Visit [godoc](http://godoc.org/github.com/google/jsonapi#MarshalManyPayload)
Takes an `io.Writer` and an slice of `interface{}`. Note, if you have a
type safe array of your structs, like,
@ -306,7 +306,7 @@ func ListBlogs(w http.ResponseWriter, r *http.Request) {
MarshalOnePayloadEmbedded(w io.Writer, model interface{}) error
```
Visit [godoc](http://godoc.org/github.com/shwoodard/jsonapi#MarshalOnePayloadEmbedded)
Visit [godoc](http://godoc.org/github.com/google/jsonapi#MarshalOnePayloadEmbedded)
This method is not strictly meant to for use in implementation code,
although feel free. It was mainly created for use in tests; in most cases,
@ -346,13 +346,13 @@ I use git subtrees to manage dependencies rather than `go get` so that
the src is committed to my repo.
```
git subtree add --squash --prefix=src/github.com/shwoodard/jsonapi https://github.com/shwoodard/jsonapi.git master
git subtree add --squash --prefix=src/github.com/google/jsonapi https://github.com/google/jsonapi.git master
```
To update,
```
git subtree pull --squash --prefix=src/github.com/shwoodard/jsonapi https://github.com/shwoodard/jsonapi.git master
git subtree pull --squash --prefix=src/github.com/google/jsonapi https://github.com/google/jsonapi.git master
```
This assumes that I have my repo structured with a `src` dir containing

2
doc.go
View File

@ -60,6 +60,6 @@ the key in the "relationships" hash for the record.
Use the methods below to Marshal and Unmarshal jsonapi.org json payloads.
Visit the readme at https://github.com/shwoodard/jsonapi
Visit the readme at https://github.com/google/jsonapi
*/
package jsonapi

View File

@ -12,7 +12,7 @@ import (
"strconv"
"time"
"github.com/shwoodard/jsonapi"
"github.com/google/jsonapi"
)
func createBlog(w http.ResponseWriter, r *http.Request) {

View File

@ -49,7 +49,7 @@ var (
// }
//
//
// Visit https://github.com/shwoodard/jsonapi#create for more info.
// Visit https://github.com/google/jsonapi#create for more info.
//
// model interface{} should be a pointer to a struct.
func UnmarshalPayload(in io.Reader, model interface{}) error {

View File

@ -93,7 +93,7 @@ func MarshalOne(model interface{}) (*OnePayload, error) {
// }
//
//
// Visit https://github.com/shwoodard/jsonapi#list for more info.
// Visit https://github.com/google/jsonapi#list for more info.
//
// models []interface{} should be a slice of struct pointers.
func MarshalManyPayload(w io.Writer, models []interface{}) error {