Coder Social home page Coder Social logo

go_exercise's Introduction

OSCS Status

一、简介

一个练手的小项目,为熟悉运用go、gin框架、websocket的使用,前端运用的是vue3

在线demo

Github仓库

二、技术使用

  • go
  • gin框架
  • websocket
  • mysql
  • docker编译部署
  • 前端nginx部署
  • shell脚本部署

三、项目结构

Project
├─ common
  └─ response.go
├─ config
  └─ app.yml
├─ config.pro
  └─ app.yml
├─ controller
  ├─ account
    ├─ ctrAccountAdd.go
    ├─ ctrAccountInfo.go
    └─ ctrAccountLogin.go
  ├─ github
    └─ ctrTrendingList.go
  ├─ message
    └─ ctrMessageList.go
  ├─ ping
    └─ ctrPing.go
  └─ ws
     └─ ctrWs.go
├─ database
  ├─ config.go
  └─ dbCon.go
├─ Dockerfile
├─ go.mod
├─ go.sum
├─ go_docker_project
├─ init.go
├─ main.go
├─ make_image.sh
├─ middleware
  ├─ token.go
  └─ utils.go
├─ model
  ├─ Account.go
  ├─ db
    ├─ init.go
    ├─ tb.go
    ├─ tbAccount.go
    ├─ tbGithubLanguage.go
    ├─ tbGithubSince.go
    ├─ tbGithubTrending.go
    └─ tbMessage.go
  ├─ githubLanguage.go
  ├─ githubTrending.go
  ├─ init.go
  ├─ Message.go
  └─ sync.go
├─ README.md
├─ route
  └─ route.go
├─ run_image.sh
├─ spider
  └─ githubTrending.go
├─ start.sh
├─ vue3chat.sh
└─ websocket
   ├─ main.go
   ├─ manager.go
   └─ ws.go

三、nginx部署

server {
        listen       80;
        server_name  api.gxming.top;
        location / {
            proxy_pass http://172.17.0.1:3000;
        }

        location ^~ /go/socket/ {
            proxy_pass http://172.17.0.1:8010;
            proxy_redirect off;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header Host $host:$server_port;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;    
            proxy_read_timeout 6000s;
        }
        location ^~ /go {
            proxy_pass http://172.17.0.1:8010;
        }
    } 

四、docker部署

FROM golang:1.16-alpine
MAINTAINER GxmProjecrt
WORKDIR  /app
COPY . .
RUN GOPROXY="https://goproxy.io" go get -d -v ./...
RUN GOPROXY="https://goproxy.io" go build -o go_docker_project -ldflags "-X database/config.c=config.pro"
ENV TZ=Asia/Shanghai
CMD ["/app/go_docker_project"]

五、shell脚本

#!/usr/bin/env bash
IMAGENAME=go_exercise_project
CONTAINERNAME=go_exercise_project_container
ARG1=$(docker ps -aqf "name=${CONTAINERNAME}")
ARG2=$(docker images -q --filter reference=${IMAGENAME})

build() {
    docker build -t ${IMAGENAME} .
}
run() {
    docker run --privileged=true --name ${CONTAINERNAME} -p 8010:8010 -itd  ${IMAGENAME}
}
restart() {
    docker restart ${CONTAINERNAME}
}

# 删除容器
if [  -n "$ARG1" ]; then
 docker rm -f $(docker stop $ARG1)
 echo "$CONTAINERNAME容器停止删除成功.....!!!"
fi

#删除镜像
if [  -n "$ARG2" ]; then
 docker rmi -f $ARG2
 echo "$IMAGENAME镜像删除成功.....!!!"
fi

build
run

echo '执行成功'

六、License

MIT

go_exercise's People

Contributors

guoxm521 avatar

Stargazers

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