bldg14 / eventual

A simple event calendar
https://eventual-client.fly.dev
MIT License
0 stars 0 forks source link

Add structconf for config mgmt #34

Closed kevinfalting closed 1 year ago

kevinfalting commented 1 year ago

Overview

In order to run the server in multiple environments, we need to support dynamic configuration via environment variables at the minimum.

Related Issues / PRs

Closes: #31

Thought Process

I imported https://github.com/kevinfalting/structconf for configuration management. This required creating a new config package and Config type, which I annotated with the appropriate struct tags.

I chose to name the environment variable PORT because that's a common env var that's set in providers like fly.io, although I couldn't find anything explicit about environment variables for the port, this may just be something we have to manually set.

I've also added the AllowedOrigins to the config, and we'll test that again once we're actually making requests from the client.

Testing Steps

Run the server and then you can make a request:

$ curl localhost:3000/api/v1/events

Which you should get back a json of events.

You can override the default value by providing the environment variable:

$ PORT=4545 go run ./cmd/eventual

You should see that it's listening on port 4545.

Run the curl again with the updated port, and get the same json result.

Risks

Since we're not testing the AllowedOrigins we may need to fix it when we begin adding the client side requests.

Screenshots / Recordings

n/a