Install the article

Installation method:

  • Install using Govendor
    • Install govendor
    go get -u github.com/kardianos/govendor
    Copy the code
    • Install gin using Govendor
      1. Go to the SRC directory in the $GOPATH directory
      2. Create a project directory. eg:studytest
      3. Go to the project directory. cd studytest
      4. Get gin using govendor
      Govendor fetch github.com/gin-gonic/[email protected]Copy the code
      1. Write test entry files.
      package main
      import "github.com/gin-gonic/gin"
      func main(a) {
          r := gin.Default()
          r.GET("/ping".func(c *gin.Context) {
              c.JSON(200, gin.H{
      	    "message": "pong",
              })
          })
          r.Run() // listen and serve on 0.0.0.0:8080
      }
      Copy the code
      1. The test. go run main.go

Problems encountered during installation

  • cannot find package “github.com/go-playground/validator/v10”
    • Solutions:
    # cd $GOPATH
    # go get "gopkg.in/go-playground/validator.v10"
    # cp -rf $GOPATH/src/gopkg.in/go-playground/validator.v10/* 
    # $GOPATH/src/vendor/github.com/go-playground/validator/v10
    # govendor add +external
    Copy the code
  • cannot find package “golang.org/x/sys/unix”
    • Solutions:
    # mkdir -p $GOPATH/src/golang.org/x
    # cd $GOPATH/src/golang.org/x
    # git clone https://github.com/golang/sys.git
    # govendor add +external
    Copy the code

Deployment of article

Drone + docker + rancher deployment:

  • Write the drone. Yml
Workspace: base: / WWW /gopath/ SRC path: gateway Pipeline: build: image: golang: Alpine3.11 Commands: -export GOPATH=/www/gopath
      - set GOARCH=amd64
      - set GOOS=linux
      - go build .
      - ls -lThe publish - test: image: alpine: 3.11.5 mirror: https://docker.mirrors.ustc.edu.cn registry: registry.cn-hangzhou.aliyuncs.com repo: from_secret: docker_repo username: from_secret: docker_username password: from_secret: docker_password tags: -test
    when:
      branch: testThe publish - prod: image: alpine: 3.11.5 mirror: https://docker.mirrors.ustc.edu.cn registry: registry.cn-hangzhou.aliyuncs.com repo: from_secret: docker_repo username: from_secret: docker_username password: from_secret: docker_password tags:${DRONE_TAG=latest}when: event: tag rancher-test: image: peloton/drone-rancher url: from_secret: rancher_url access_key: from_secret: rancher_access_key secret_key: from_secret: rancher_secret_key service: testing/gateway docker_image: {docker_image} // start_first:true
    confirm: true
    when:
      branch: test
Copy the code
  • Write Dockerfile
The FROM alpine: 3.11.5 ENV WEB_ROOT = / WWW/below# Update APK source 123
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
# apk update
RUN apk update
Create a root directory
RUN mkdir -p ${WEB_ROOT}
COPY ./gateway ${WEB_ROOT}
WORKDIR ${WEB_ROOT}
RUN chmod +x gateway
CMD ["/www/wwwroot/gateway"."-g"."daemon off;"]
STOPSIGNAL SIGQUIT
Copy the code

Deploy the results

Access to the results

End and spend