/go_json

golang study.

Primary LanguageGo

Golang

Serials

Basic Info

download tarball
tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz
export go path in /etc/profile

Closure

Share

Http

Best Practice

Reflect

Interface

Database

Cache

Microservice

Third-Party Libraries

Web Server Framework: beego

Web Server Framework: gin

Docker Image

gin Development

  • use <codegangsta/gin> to do golang web application live reloading with docker
  • docker file
# Version: 1.0.0
# Create Time: 2018-07-20
# Author: Jason Tu
# Description: Microservice Audit log img

FROM golang:latest

# Install golang library
RUN go get github.com/gin-gonic/gin && go get github.com/go-sql-driver/mysql \
    && go get github.com/codegangsta/gin

# Expose the application on port 8080
EXPOSE 8080

# Set the entry point of the container to the bee command that runs the
# application and watches for changes
CMD ["gin", "run", "*.go"]
# or CMD ["/bin/bash"]
  • commands
docker run -i -d --rm --name auditlog_ms -p 8080:3000 -v /root/gin_playground/auditlog_ms:/go/src/auditlog_ms -w /go/src/auditlog_ms auditlog_ms:base
or
docker run -it --rm --name auditlog_ms -p 8080:3000 -v /root/gin_playground/auditlog_ms:/go/src/auditlog_ms -w /go/src/auditlog_ms auditlog_ms:base

gin Deploy

# Version: 1.0.0
# Create Time: 2018-07-20
# Author: Jason Tu
# Description: Microservice Audit log img

FROM golang:latest

# Create the directory where the application will reside
RUN mkdir /app

ADD auditlog_ms /app/auditlog_ms
ADD conf /app/conf

WORKDIR /app

EXPOSE 8080

# Set the entry point of the container to the application executable
ENTRYPOINT /app/auditlog_ms
  • commands
docker run -i -d --rm --name auditlog_ms_prod -p 8081:3001 auditlog_ms:prod

Dependency Management

go get -u github.com/kardianos/govendor
# then build govendor

# goto src code folder
govendor init
govendor add +external
# commit the library code