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 downloadBuild and Run
$ go build && ./go-api-exampleRun
$ go run .Test
$ go testBuild
$ docker build -t go-api-example .Run server
$ docker run --rm -p 8000:8000 go-api-exampleLocal
$ go mod download
$ go testDocker
$ 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