go-mux

command module
v0.0.0-...-e6a1ed5 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2020 License: MIT Imports: 9 Imported by: 0

README

Golang Mux Demo

Run locally

  • Start postgres
  • Prepare environment, fill DB parameters:
$ cp env-sample .env
$ $EDITOR .env
$ source .env
  • Create the public IPs, one for loadbalancer and another for ingress
gcloud compute addresses create go-mux-api-ip-ing --global
gcloud compute addresses create go-mux-api-ip-lb --region us-west1
  • Run PostgreSQL container and create the databases or use docker-compose

  • Docker

$ docker run --name postgres-db -p 5432:5432 -e POSTGRES_PASSWORD=${APP_DB_PASSWORD} -d postgres
$ echo "SELECT 'CREATE DATABASE ${APP_DB_NAME}' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = '${APP_DB_NAME}')\gexec" | \
psql "user=${APP_DB_USERNAME} password=${APP_DB_PASSWORD} host=127.0.0.1 port=5432"
$ echo "SELECT 'CREATE DATABASE ${TEST_DB_NAME}' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = '${TEST_DB_NAME}')\gexec" | \
psql "user=${TEST_DB_USERNAME} password=${TEST_DB_PASSWORD} host=127.0.0.1 port=5432"
  • Docker-compose
$ docker-compose build
$ docker-compose up -d
  • Build and run:
$ go get -u github.com/gorilla/mux github.com/go-sql-driver/mysql
$ go build -o go-mux-api.bin
$ ./go-mux-api.bin

Server is listening on localhost:8010

  • GKE Setup

Create the regional IP for the LoadBalancer

$ gcloud compute addresses create go-mux-api-ip --region us-west1

Test

$ go test -v
=== RUN   TestEmptyTable
--- PASS: TestEmptyTable (0.01s)
=== RUN   TestGetNonExistentProduct
--- PASS: TestGetNonExistentProduct (0.00s)
=== RUN   TestCreateProduct
--- PASS: TestCreateProduct (0.01s)
=== RUN   TestGetProduct
--- PASS: TestGetProduct (0.01s)
=== RUN   TestUpdateProduct
--- PASS: TestUpdateProduct (0.01s)
=== RUN   TestDeleteProduct
--- PASS: TestDeleteProduct (0.01s)
PASS
ok      _/home/gustavo/GIT/gfnord/go-mux        0.051s

License

The project is open-sourced software licensed under the MIT license.

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