GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - Tech-With-Tim/cdn: CDN for the Tech With Tim website using Go

BranchesTags
Open more actions menu

Latest commit

 

History

112 Commits
112 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
api
api
 
 
cache
cache
 
 
db
db
 
 
docs
docs
 
 
models @ af151e0
models @ af151e0
 
 
server
server
 
 
utils
utils
 
 
.dockerignore
.dockerignore
 
 
.gitignore
.gitignore
 
 
.gitmodules
.gitmodules
 
 
Dockerfile
Dockerfile
 
 
LICENSE
LICENSE
 
 
Makefile
Makefile
 
 
README.md
README.md
 
 
codecov.yml
codecov.yml
 
 
cover.sh
cover.sh
 
 
docker-compose.yml
docker-compose.yml
 
 
go.mod
go.mod
 
 
go.sum
go.sum
 
 
main.go
main.go
 
 
sqlc.yaml
sqlc.yaml
 
 
test.sh
test.sh
 
 

Repository files navigation

Project logo

Tech With Tim - CDN

Status
codecov Lint & Test GitHub Issues GitHub Pull Requests Licence Discord

CDN for the Tech With Tim website using Go

📝 Table of Contents

  • 🏁 Getting Started
    • Environment variables
    • Running
  • 🐳 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=30
  • SECRET_KEY is the key used for the JWT token encoding.
  • MAX_FILE_SIZE is 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 test

If 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

  • Go - Language
  • go-chi - Router
  • sqlc - Database Query Helper

✍️ Authors

See the list of contributors who participated in this project.

About

CDN for the Tech With Tim website using Go

cdn.twtcodejam.net

Topics

cdngo-chigolangpostgres

Resources

Readme
MIT license
Activity
Custom properties

Stars

12 stars

Watchers

1 watching

Forks

4 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.