Example of a go API with a password validation endpoint and tests. The service runs on port 8000.
The correct credentials are:
username: technicallyjosh
password: testing123
Install Dependencies
$ go mod download
Build and Run
$ go build && ./go-api-example
Run
$ go run .
Test
$ go test
Build
$ docker build -t go-api-example .
Run server
$ docker run --rm -p 8000:8000 go-api-example
Local
$ go mod download
$ go test
Docker
$ docker run --rm go-api-example /bin/bash -c "go test"
Verifies a password for a user. In this example it's more like a login without assigning a token or session etc... Normally when just verifying a user's password, we'd accept a signed token in the header and get the username or id from it.
Property | Type | Required |
---|---|---|
username | string |
Yes |
password | string |
Yes |
$ curl -i -XPUT localhost:8000/users/verify -d '
{
"username": "technicallyjosh",
"password": "testing123"
}'; echo