go-mux-api

command module
v0.0.0-...-5ef0f71 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2022 License: MIT Imports: 12 Imported by: 0

README

go-mux-api

Learning exercise using Go, Mux, Postgres and Docker to create a basic CRUD API.

Resources

DB Setup

Install go migrate (Go 1.16+):

go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest

Setup initial migration (don't need to run this again, but can use as reference for future migrations):

migrate create -ext sql -dir db/migrations -seq create_items_table

Run the migrations:

export POSTGRESQL_URL="postgres://risky:rainy2@localhost:5432/ror2?sslmode=disable"
migrate -database ${POSTGRESQL_URL} -path db/migrations up
Tidbits

If you need to reset the database completely and reinitialize (eg. with a different user/pass or db name) don't forget to remove the volume:

docker container prune
docker network prune
docker volume prune
docker volume rm -f go-mux-api_data

Run Locally

docker compose up --build
Verification

Test connecting to DB by exec'ing into the container while it's running:

docker exec -it postgres psql -d ror2 -U risky

Test the API with cURL:

curl http://localhost:8010/items
GraphQL

This API also supports graphql queries like so:

curl -X POST -H "Content-Type: application/json" \
-d '{"query": "{list{id,name,description,quality}}" }' \
http://localhost:8010/graphql/item

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL