- create main directory
- create main.go file
- declare package main
- declare main function
- import fmt package
- make a call to fmt.Println and print "Hello world, my name is <your_name_here>"
- create datamodel.go file
- create AuthorDto struct with the following fields:
- UUID string
- FirstName string
- LastName string
- Birthday string
- Death string
- create BookDto struct with the following fields:
- UUID string
- Title string
- NoPages int
- ReleaseDate string
- Author AuthorDto
- create a slice of AuthorDto which will hold all authors in the system
- create a slice of BookDto which will hold all books in the system
- map AuthorDto.UUID field to uuid field in the resulting JSON
- map AuthorDto.FirstName field to firstName field in the resulting JSON
- map AuthorDto.LastName field to lastName field in the resulting JSON
- map AuthorDto.Birthday field to birthday field in the resulting JSON
- map AuthorDto.Death field to death field in the resulting JSON
- map BookDto.UUID field to uuid field in the resulting JSON
- map BookDto.Title field to title field in the resulting JSON
- map BookDto.NoPages field to noPages field in the resulting JSON
- map BookDto.ReleaseDate field to releaseDate field in the resulting JSON
- map BookDto.Author field to author field in the resulting JSON
- create model package
- move datamodel.go in model folder
- create importer package
- create authors.json file in importer folder
- add an array of authors with sample data in JSON format
- create books.json file in importer folder
- add an array of books with sample data in JSON format
- create dataImporter.go file in importer folder
- import encoding/json package
- import io/ioutil
- create a function named ImportAuthors that reads authors.json file and return a slice of authors
- create a function named ImportBooks that reads the books.json file and returns a slice of books
- print all authors to the STDOUT
- print all books to the STDOUT
- create web package
- create webserver.go
- import net/http
- read listening port from API_PORT environment variable, defaulting to 8000
- define a http.Handler function that will handle the incoming HTTP requests to the web server
- launch the web server on API_PORT port by calling ListenAndServe
- if the web server returns an error, exit the application
- change the path of the REST endpoint from /test to /books
- configure the handler to respond only to GET methods
- marshal the books array to JSON bytes
- convert the JSON bytes to string
- set the "Content-Type" response header to "application/json"
- when /books endpoint is hit, return all books previously loaded from the JSON file
#Part 3 - Add error handling and logging, improve performance with Go routines