GithubHelp home page GithubHelp logo

gokedex's Introduction

Gokedex - a pokédex written in Go

This is an sample project for learning Go.
You can perform CRUD operations on a PostgreSQL database via RestAPI.
This is written in Microservice-Arch, so you could easily add a Frontend e.g. with React.

The Stack

Language: Go
Frameworks: Gin (RestAPI), pgx (driver), Swagger (docs)
Database: PostgreSQL
Containerization: Docker
IDE: VSCode

How to run

Get a postgresql-Container:
Basic command for running a postgres container:

docker run --name some-postgres -p 5432:5432 -e POSTGRES_PASSWORD=mysecretpassword -v postgres_data:/var/lib/postgresql/data -d postgres

We can use this container to run the app locally with go run main.go.
If we want to containerize the app and run it, we need to make some adjustments.

Build the app container: Use the Dockerfile

docker build -t gokedocker .

Note how this uses multi-stage build to create a minimal image.

Create Network:
To make the containers be able to talk to each other, we need to create a dedicated network

docker network create gokedex

Run the containers in the network: For the postgres:

docker run --name some-postgres -p 5432:5432 -e POSTGRES_PASSWORD=mysecretpassword -v postgres_data:/var/lib/postgresql/data -d --network=gokedex postgres

For the app:

docker run -dp 8080:8080 -e DATABASE_URL=postgres://postgres:mysecretpassword@some-postgres:5432/ --network=gokedex gokedocker

Note how we pass the hostname in the DATABASE_URL, using the container name!

We could aswell use docker-compose to build the stack.

Learnings

  • lowercase function definitions are considered as unexported, so if creating packages you have to write them Uppercase to use them in other packages.
  • container networking
  • Structure of Go apps
  • SQL

gokedex's People

Contributors

xamma avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.