This research project was created to explore Go by creating a simple web service.
Build and run:
go build
go run .
Use your browser or favorite tool to interact with the web service on http://localhost:8080/
See cmd/service/ws.go
for the various endpoints.
Add an article using the service end point
curl http://localhost:8080/articles \
--include \
--header "Content-Type: application/json" \
--request "POST" \
--data '{"id":"4","title":"Jaws","author":"someone","wordCount":7331}'
Things learned:
-
In order for a Go method to be exported from its package, it must start with a capital letter. :-/
-
you import packages (whole directories or external references) and not files
-
make()
vsnew()
-
slices vs arrays Kind of like lists vs fixed size array. Manipulate the slice with the
append
method. Withmake()
can cap the size of the slice. Slices are ordered. Can use thesort
package to sort the list.Sorting a slice ascending and descending:
var numbers = []int{5, 4, 8, 3, 2, 1} sort.Ints(numbers) fmt.Println(numbers) sort.Sort(sort.Reverse(sort.IntSlice(numbers))) fmt.Println(numbers)
-
super cool, easy to swap items
s[i], s[n] = s[n], s[i]
go mod init path.to/module
go run .
go build .
go mod tidy
go install
go test
go get
Some more things I'm going to tackle with this project:
- parse out the result in the time service
- add another end point that uses/does the parsing
- gRPC / HTTP2 endpoints
- GraphQL
- another one to utilize the time service, specify what you want back
- HTTPS
- how to create and run unit tests
- how to use with swagger.io
- Authentication / Authorization: API key? JWT
- read from a configuration file
- log to an application log file
- write process ID to file
recover
error handling- fuzzing test example when it is released into production
- Go: The Complete Developer's Guide (Golang)
- REST based microservices API development in Golang
- gRPC GoLang Master Class: Build Modern API & Microservices
- Go Bootcamp: Master Golang with 1000+ Exercises and Projects
- Go Lang tutorial
- A Tour of Go
- Effective Go
- Go Standard Library
- Gin web services
- JSON-to-Go
- Concurrency is not Parallelism video (Slides)
- Go Standard Project Layout
- Fyne - cross platform GUI
- Go Kit framework for microservices