You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.4 KiB
Markdown

# Go Maths students API
1 year ago
A simple Go API whose only purpose is to check whether an user is a Maths student or not.
1 year ago
## Prerequisites
1 year ago
- An environment variable `AUTHPDS_TOKEN` containing the authentication token for the external API.
- An environment variable named `SECRET` containing the secret token for authorization.
## Development
### Development
```bash shell
# Create a ".env" file from the given template and update as needed
$ cp .env.example .env
# Start the server
$ go run -v .
# Build to binary
$ go build -v -o ./bin/go-maths-api .
```
### Deploy
1 year ago
To build and run the image from the provided `Dockerfile`:
```bash shell
# Create a ".env" file from the given template and update as needed
$ cp .env.example .env
$ docker build -t go-maths-api .
$ docker run -d --restart always -p 8080:8080 --name go-maths-api go-maths-api
```
1 year ago
### Client Usage
1 year ago
An example request to the local Docker image (with `SECRET` defined in your environment):
```bash shell
$ curl "localhost:8080/check-maths-user?user=f.minnocci" -H "Authorization: Bearer $SECRET"
1 year ago
```
Successful JSON response:
```json
1 year ago
{
"result": true
}
```
## Notes
- TODO: Add a small 1-day cache
- Original code idea: <https://github.com/Unipisa/dm-cups/blob/d304b95d5b4aabafca1cc2fde0f828ea93238255/dm-cups#L61>
- The first iteration of this project was generated this ChatGPT conversation: <https://chat.openai.com/share/de5438e8-660c-49c4-80de-7aae3df870cf>