24_bookstore_json_out

command
v0.0.0-...-baf0b24 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2020 License: MIT Imports: 2 Imported by: 0

README

THIS IS POSTGRES

We are going to rebuild our postgres example using mongo instead.

First we need to extract our the records from the books table in our bookstore database.

The code in this folder has a new route which will give you the following json:

[{"Isbn":"978-1505255607","Title":"The Time Machine","Author":"H. G. Wells","Price":5.99},{"Isbn":"978-1503261960","Title":"Wind Sand \u0026 Stars","Author":"Antoine","Price":14.99},{"Isbn":"978-1503261961","Title":"West With The Night","Author":"Beryl Markham","Price":14.99}]

notice \u0026

That is valid JSON encoding. That is the unicode escape. & doesn't have to be encoded, but Go does this so we can just let it be. JSON encoders / decoders know how to deal with it.

To see this JSON output

turn on postgres

Make sure postgres is on.

run your server
go run *.go
get the json of the books
curl -i localhost:8080/books/json

Note

Remember: You need to capitalize to have a variable, type, or func exported from a package

run the application and make a request

curl -i localhost:8080/books
curl -i -X POST -d "isbn=978-1470184841&title=Metamorphosis&author=Franz Kafka&price=5.90" localhost:8080/books/create/process

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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