Go practice project to show how data flows between different layers
Currently in the dataflow.go file, a sqlite database is connected, a table is created, and some data is inserted into the table.
Tasks:
Create your own directory with your user name and copy the dataflow.go to your own directory
Currently, all DB operations are executed without error handling. Find out which function call will return error and add error handling (eg. print out the error and exit).
Create a structure "People" to hold the intial data and and use the structure member in the statement.Exec() call.
Put the structured People data into a slice of "Peoples", and use for loop to execute statement.Exec() call.
Move the People structure into another go file as a new package, and import People from that package.
Query from DB the inserted data and print out
Replace the database/sql with package github.com/jmoiron/sqlx
use sqlx db.Select to query DB into the Peoples slice
Print out the Peoples slice to a json array in the standard output (using "encoding/json") package
Add json tags to the People structure, that when marshal the People structure,
- id is omitted
- all keys are in lower case: eg: firstname, instead of Firstname
Create a new structure PPeople, which includes all the fields of People, and and a new field "Name"
Add interface "Present()" to the PPeople structure, which will combile the "Firstname" and "Lastname" to the "Name" field, and then print the whole structure to JSON
Using "net/http" to run an http server in dataflow.go, which can respond "pong" when getting http://localhost:8080/ping request
Implement handler for "/peoples" request, and return the PPeople slice in JSON array.
Implement unit tests for the code written and show the code coverage.