Tech With Tim - CDN
CDN for the Tech With Tim website using Go
๐ Table of Contents
- ๐ Getting Started
- ๐ณ Running with Docker
- ๐จ Tests
- ๐ Licence
- โ๏ธ Built Using
- โ๏ธ Authors
๐ Getting Started
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See Running with Docker if you want to setup the CDN faster with Docker. ( Docker is optional )
Environment variables
Set the environment variables. Start by writing this in a file named app.env and test.env:
(test.env is required for running tests)
app.env and test.env should look like this:
DB_URI=postgres://user:password@localhost:5432/dbname?sslmode=disable
SECRET_KEY=secret
MAX_FILE_SIZE=30SECRET_KEYis the key used for the JWT token encoding.MAX_FILE_SIZEis the maxiumum file size allowed in asset upload (in mb)
Running
- To create the Postgres container -
make postgres - To create the db -
make createdb - To drop db -
make dropdb
Run go mod tidy to install packages
CLI commands
go run main.go migrate_up
go run main.go dropdb
go run main.go migrate_steps --steps int
go run main.go generate_docs
go run main.go runserver --host localhost --port port (localhost, 5000 are default)
To run migrations on the test database
go run main.go migrate_up -t
go run main.go dropdb -t
go run main.go migrate_steps -t --steps int
Use the make file, its your best friend ๐
Make commands -
If you are on windows please use Git Bash or WSL. You also have to install Make for Windows
To install Make for Windows run winget install GnuWin32.Make
make postgres # Creates docker container for postgres12
# Reads env variables from app.env
make createdb # Creates the db in the postgres container
make dropdb # Drops the db
make migrate_up # Migrates to the latest schema
make sqlc_generate # Generates sqlc code if you write queries
make generate_docs # Generates documentation
make test # Tests your code and shows coverage
# Its a big output make sure to read it all๐ณ Running with Docker
Start the cdn with docker-compose up
๐๏ธDocs
While adding new endpoints, you need add docs in the form of comments. For example:
/*
Response: String
URL Parameters: None
Request Body:
- Name: username
- Type: String
- Description: "Username to register so and so . . ."
Description: "Returns `Hello, World` when called."
*/
func GetAllAssets(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(statusCode)
json.NewEncoder(w).Encode("Hello, World")
}And you will need to update the routes variable in routes.go
๐จ Tests
There are two methods to test the cdn -
make testIf you don't have make installed -
go run main.go migrate_up -t
go test ./... -v When you contribute, you need to add tests for the features you add.
โ๏ธ Built Using
โ๏ธ Authors
See the list of contributors who participated in this project.

