Based on this great blog of Soham Kamani.
# Run unit tests
go test -v
# Run web app
go run main.go bird_handlers.go store.go
Browse to
wget localhost:8080
wget localhost:8080/hello
wget localhost:8080/assets/
Use dep
to manage dependencies.
# Install all dependencies
dep ensure
docker build -t gowebapp .
docker run -it --rm -p 8080:8080 --name my-running-gowebapp gowebapp
When you develop new code, you will need to remove the image in order to get it rebuild. (COPY in the Dockerfile does not detect changes?)
docker image rm gowebapp
docker pull postgres
# Start postgress container
docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres
# Connect using psql
docker run -it --rm --link some-postgres:postgres postgres psql -h postgres -U postgres
#> password: mysecretpassword
Play around with SQL.
-- Create the database
CREATE DATABASE bird_encyclopedia;
-- Enter the database
\c bird_encyclopedia
-- Create table
CREATE TABLE birds (
id SERIAL PRIMARY KEY,
species VARCHAR(256),
description VARCHAR(1024)
);
-- Get info
\d
\d birds
select * from birds;
-- Insert a value
INSERT INTO birds (species, description) VALUES ('kanarie', 'Small yellow brid');
select * from birds;
select species, description from birds;
docker-compose up
You can verify if the database is initialized using psql:
docker exec -it webappfullstackgodocker_db_1 psql -d bird_encyclopedia -U postgres -c "select * from birds;"
Cleaning things:
docker-compose -f docker-compose.yml rm --force
connString := "host=db user=postgres password=secret dbname=bird_encyclopedia sslmode=disable"
- Add unit test for store
- Add CI flow, Travis CI or Cirlce CI?