An exercise into how to create an HTTP service using GO, following guidance from:
- https://go.dev/doc/modules/layout
- https://github.com/golang-standards/project-layout/blob/master/README.md
- https://grafana.com/blog/2024/02/09/how-i-write-http-services-in-go-after-13-years
Then gave up doing vanilla Go HTTP server; because I'm a wimp and used a framework instead:
Went back a day later and continued to re-read the "after 13 years" blog post to create the Hello, World!
http sample.
Regardless, I have decided to continue with gin
itself, but following the coding styles suggested; such as not storing dependencies in a struct
but passing them through the functions.
- Go 1.25
- Mockery 2.53 https://github.com/vektra/mockery/releases
This project attempts to follow the standard Go project layout as defined here: https://github.com/golang-standards/project-layout/blob/master/README.md
├── cmd # Main applications for this project.
│ └── server
│ └── main.go
├── internal # Private application and library code.
│ ├── app
│ │ ├── token-exchange
│ │ ├── token-introspection
│ │ ├── token-revocation
│ │ └── ...etc
│ └── pkg
│ ├── client
│ ├── grant
│ ├── scope
│ └── ...etc
├── scripts
│ └── http # Jetbrains HTTP Client requests
└── README.md
The standard Go approach to unit testing
go test -v ./...
To include the benchmark tests
go test -v ./... -bench .
To only run the benchmark tests
go test -v ./... -bench . -run ^$
Using mockery, we can auto-generate the standard mocks for interfaces.
go generate
Which is just a different way to doing
mockery
An OAuth server, using mostly the Gin web framework that wraps around the Go http library.
go build ./cmd/server
./server
So yeah, the password grant is deprecated; but it's a quick lazy way to start.
curl -vvv -X POST -H 'Content-Type: application/x-www-form-urlencoded' -u 'aardvark:badger' -d 'grant_type=password&scope=basic&username=aardvark&password=P%4055w0rd' http://127.0.0.1:8080/token