A SaaS that shortens url to make it cleaner to share.
Install migrate for PostgreSQL migrations:
go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
Install SQLc for generating Go code from SQL queries:
go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
Run postgres in a docker container:
docker run --name postgres-urls \
-e POSTGRES_USER=user \
-e POSTGRES_PASSWORD=pass \
-e POSTGRES_DB=url_db \
-p 5432:5432 \
-d postgres
Run redis in a docker container:
docker run --name redis-url \
-p 6379:6379 \
-d redis
migrate -path database/migrate \
-database "postgres://user:pass@localhost:5432/url_db?sslmode=disable" \
up
migrate -path database/migrate \
-database "postgres://user:pass@localhost:5432/url_db?sslmode=disable" \
drop -f
Make sure to set the timezone in PostgreSQL to UTC. You can do this by running the following command in the PostgreSQL shell:
ALTER DATABASE url_db SET timezone TO 'UTC';
cp config.example.toml config.toml
And edit the config.toml
file with your database and redis credentials.
go run main.go