Giter Site home page Giter Site logo

rest-go-demo's Introduction

TUTORIAL

Create a GO REST API with MySQL and deploy on Docker Image

Create project and dependencies

mkdir rest-go-demo && cd rest-go-demo
go mod init rest-go-demo
go get gitlab.com/avarf/getenvs
go get github.com/gorilla/mux
go get github.com/jinzhu/gorm
go get github.com/go-sql-driver/mysql

Initialize MySQL database

Use init scripts (optional)

-v db/scripts:/docker-entrypoint-initdb.d/

docker network create rest-go-demo-net
mkdir -p db/data
mkdir -p db/conf
cat >> db/conf/mysql-custom.cnf <<EOL
[mysqld]
max_connections=250
EOL
docker run -d --rm --name mysql -p 3306:3306 --network=rest-go-demo-net -e MYSQL_USER=demo -e MYSQL_PASSWORD=demo -e MYSQL_DATABASE=demo -e MYSQL_ROOT_PASSWORD=demo -v $(pwd)/db/data:/var/lib/mysql/ -v $(pwd)/db/conf/mysql-custom.cnf:/etc/mysql/conf.d -d mysql/mysql-server

Run the project

go run main.go

Compile the executable

go build -a -o demo main.go

Run the app

./demo

Build Docker image

docker build -t rest-go-demo .
docker run --rm -it -p 8080:8080 --network=rest-go-demo-net -e MYSQL_HOST=mysql rest-go-demo

Testing using Postman Collection

Import collections on testing/rest-go-demo.postman_collection.json

rest-go-demo's People

Contributors

marcelomrwin avatar

Watchers

James Cloos avatar  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.