From 4f458591e860c5f6a28e5fec783ea87b4b8ce0c9 Mon Sep 17 00:00:00 2001 From: wenjianzhang Date: Wed, 10 Aug 2022 00:47:42 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=20docs=F0=9F=93=9D:=20Update=20README.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index da4e778..e0fa80d 100644 --- a/README.md +++ b/README.md @@ -270,7 +270,8 @@ npm run dev - + + From dc625997c4547559d2a73a37f8f1301b1bc255ad Mon Sep 17 00:00:00 2001 From: wenjianzhang Date: Wed, 10 Aug 2022 01:00:34 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=20docs=F0=9F=93=9D:=20Update=20README.Zh-c?= =?UTF-8?q?n.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.Zh-cn.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.Zh-cn.md b/README.Zh-cn.md index 2f9049b..20fb27f 100644 --- a/README.Zh-cn.md +++ b/README.Zh-cn.md @@ -284,7 +284,8 @@ npm run dev - + + ## JetBrains 开源证书支持 From e8b9db1df57785e3ecdcd86086b1a753c48e440e Mon Sep 17 00:00:00 2001 From: zhaoyidong Date: Sat, 13 Aug 2022 17:37:55 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E4=B8=AD=E9=97=B4=E4=BB=B6=E9=87=8D=E5=A4=8D=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit go-admin app -n 创建目录,重复初始化会导致获取不到body中的参数 --- template/router.template | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/template/router.template b/template/router.template index 010bb03..247ca32 100644 --- a/template/router.template +++ b/template/router.template @@ -34,9 +34,6 @@ func InitRouter() { os.Exit(-1) } - r.Use(common.Sentinel()). - Use(common.RequestId(pkg.TrafficKey)) - common.InitMiddleware(r) // the jwt middleware authMiddleware, err := common.AuthInit() if err != nil { @@ -75,4 +72,4 @@ func checkRoleRouter(r *gin.Engine, authMiddleware *jwtauth.GinJWTMiddleware) { for _, f := range routerCheckRole { f(v, authMiddleware) } -} \ No newline at end of file +} From ea9e3d2fe18d8c093094d8914a9838e0d1d7b631 Mon Sep 17 00:00:00 2001 From: wanghaima Date: Sun, 14 Aug 2022 23:32:58 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E7=BC=96=E5=86=99dockerfile=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E8=84=9A=E6=9C=AC=20=E7=BC=96=E8=BE=91shell=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- Dockerfile | 29 +++++++++++++++-------------- Dockerfilebak | 28 ++++++++++++++++++++++++++++ Makefile | 40 +++++++++++++++++++++++++++++++++++++++- docker-compose.yml | 19 +++++++++++++++++++ restart.sh | 9 +++++++++ stop.sh | 4 ++++ 7 files changed, 115 insertions(+), 16 deletions(-) create mode 100644 Dockerfilebak create mode 100644 docker-compose.yml create mode 100644 restart.sh create mode 100644 stop.sh diff --git a/.gitignore b/.gitignore index ce6fd6b..4f654db 100644 --- a/.gitignore +++ b/.gitignore @@ -4,11 +4,11 @@ static/uploadfile main.exe go-admin +go-admin.exe temp/ !temp vendor config/settings.dev.yml -go-admin common/middleware/demo.go config/settings.dev.*.yml config/settings.dev.*.yml.log diff --git a/Dockerfile b/Dockerfile index c5e33a5..c7e2926 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,28 +1,29 @@ FROM golang:alpine as builder -MAINTAINER lwnmengjing +MAINTAINER haimait -ENV GOPROXY https://goproxy.cn/ +WORKDIR /work -WORKDIR /go/release -#RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories -RUN apk update && apk add tzdata +RUN go env -w GOPROXY=https://goproxy.cn,direct && go env -w CGO_ENABLED=0 +COPY go.mod go.sum ./ +RUN go mod download -COPY go.mod ./go.mod -RUN go mod tidy COPY . . -RUN pwd && ls +RUN go build -o go-admin main.go -RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -a -installsuffix cgo -o go-admin . -FROM alpine +FROM alpine:latest +# change timezone +RUN apk add --no-cache tzdata && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" > /etc/timezone -COPY --from=builder /go/release/go-admin / +WORKDIR /go-admin-api -COPY --from=builder /go/release/config/settings.yml /config/settings.yml +COPY --from=builder /work/go-admin ./ +COPY --from=builder /work/config ./config +COPY --from=builder /work/static ./static +COPY --from=builder /work/temp ./temp -COPY --from=builder /usr/share/zoneinfo/Asia/Shanghai /etc/localtime EXPOSE 8000 -CMD ["/go-admin","server","-c", "/config/settings.yml"] \ No newline at end of file +CMD ["./go-admin","server","-c", "config/settings.dev.yml"] diff --git a/Dockerfilebak b/Dockerfilebak new file mode 100644 index 0000000..c5e33a5 --- /dev/null +++ b/Dockerfilebak @@ -0,0 +1,28 @@ +FROM golang:alpine as builder + +MAINTAINER lwnmengjing + +ENV GOPROXY https://goproxy.cn/ + +WORKDIR /go/release +#RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories +RUN apk update && apk add tzdata + +COPY go.mod ./go.mod +RUN go mod tidy +COPY . . +RUN pwd && ls + +RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -a -installsuffix cgo -o go-admin . + +FROM alpine + +COPY --from=builder /go/release/go-admin / + +COPY --from=builder /go/release/config/settings.yml /config/settings.yml + +COPY --from=builder /usr/share/zoneinfo/Asia/Shanghai /etc/localtime + +EXPOSE 8000 + +CMD ["/go-admin","server","-c", "/config/settings.yml"] \ No newline at end of file diff --git a/Makefile b/Makefile index 135c7e7..812402b 100644 --- a/Makefile +++ b/Makefile @@ -3,10 +3,40 @@ PROJECT:=go-admin .PHONY: build build: CGO_ENABLED=0 go build -ldflags="-w -s" -a -installsuffix -o go-admin . + +# make build-linux build-linux: - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -a -installsuffix -o go-admin . + @docker build -t go-admin:latest . + @echo "build successful" + build-sqlite: go build -tags sqlite3 -ldflags="-w -s" -a -installsuffix -o go-admin . + +# make run +run: + # delete go-admin-api container + @if [ $(shell docker ps -aq --filter name=go-admin --filter publish=8000) ]; then docker rm -f go-admin; fi + + # 启动方法一 run go-admin-api container docker-compose 启动方式 + # 进入到项目根目录 执行 make run 命令 + @docker-compose up -d + + # 启动方式二 docker run 这里注意-v挂载的宿主机的地址改为部署时的实际决对路径 + #@docker run --name=go-admin -p 8000:8000 -v /home/code/go/src/go-admin/go-admin/config:/go-admin-api/config -v /home/code/go/src/go-admin/go-admin-api/static:/go-admin/static -v /home/code/go/src/go-admin/go-admin/temp:/go-admin-api/temp -d --restart=always go-admin:latest + + @echo "go-admin service is running..." + + # delete Tag= 的镜像 + @docker image prune -f + @docker ps -a | grep "go-admin" + +stop: + # delete go-admin-api container + @if [ $(shell docker ps -aq --filter name=go-admin --filter publish=8000) ]; then docker-compose down; fi + #@if [ $(shell docker ps -aq --filter name=go-admin --filter publish=8000) ]; then docker rm -f go-admin; fi + #@echo "go-admin stop success" + + #.PHONY: test #test: # go test -v ./... -cover @@ -14,3 +44,11 @@ build-sqlite: #.PHONY: docker #docker: # docker build . -t go-admin:latest + +# make deploy +deploy: + + #@git checkout master + #@git pull origin master + make build-linux + make run \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..41d94de --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,19 @@ +version: '3.8' +services: + go-admin-api: + container_name: go-admin + image: go-admin:latest + privileged: true + restart: always + ports: + - 8000:8000 + volumes: + - ./config/:/go-admin-api/config/ + - ./static/:/go-admin-api/static/ + - ./temp/:/go-admin-api/temp/ + networks: + - myweb +networks: + myweb: + driver: bridge + diff --git a/restart.sh b/restart.sh new file mode 100644 index 0000000..53ea7b5 --- /dev/null +++ b/restart.sh @@ -0,0 +1,9 @@ +#!/bin/bash +echo "go build" +go mod tidy +go build -o go-admin main.go +echo "kill go-admin service" +killall go-admin # kill go-admin service +nohup ./go-admin server -c=config/settings.dev.yml >> access.log 2>&1 & #后台启动服务将日志写入access.log文件 +echo "run go-admin success" +ps -aux | grep go-admin \ No newline at end of file diff --git a/stop.sh b/stop.sh new file mode 100644 index 0000000..6dd9dc4 --- /dev/null +++ b/stop.sh @@ -0,0 +1,4 @@ +#!/bin/bash +killall go-admin # kill go-admin service +echo "stop go-admin success" +ps -aux | grep go-admin \ No newline at end of file From 62d9084ee8bf0f95e9cdad3233092a0bd24231e0 Mon Sep 17 00:00:00 2001 From: zhaoyidong Date: Tue, 16 Aug 2022 11:41:28 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=A8=A1=E6=9D=BFget=20u?= =?UTF-8?q?pdate=20delete=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- template/v4/no_actions/apis.go.template | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/template/v4/no_actions/apis.go.template b/template/v4/no_actions/apis.go.template index 08c0926..8e85d8c 100644 --- a/template/v4/no_actions/apis.go.template +++ b/template/v4/no_actions/apis.go.template @@ -65,7 +65,7 @@ func (e {{.ClassName}}) GetPage(c *gin.Context) { // @Summary 获取{{.TableComment}} // @Description 获取{{.TableComment}} // @Tags {{.TableComment}} -// @Param id path string false "id" +// @Param id path int false "id" // @Success 200 {object} response.Response{data=models.{{.ClassName}}} "{"code": 200, "data": [...]}" // @Router /api/v1/{{.ModuleName}}/{id} [get] // @Security Bearer @@ -135,6 +135,7 @@ func (e {{.ClassName}}) Insert(c *gin.Context) { // @Tags {{.TableComment}} // @Accept application/json // @Product application/json +// @Param id path int true "id" // @Param data body dto.{{.ClassName}}UpdateReq true "body" // @Success 200 {object} response.Response "{"code": 200, "message": "修改成功"}" // @Router /api/v1/{{.ModuleName}}/{id} [put] @@ -167,7 +168,7 @@ func (e {{.ClassName}}) Update(c *gin.Context) { // @Summary 删除{{.TableComment}} // @Description 删除{{.TableComment}} // @Tags {{.TableComment}} -// @Param ids body []int false "ids" +// @Param data body dto.{{.ClassName}}DeleteReq true "body" // @Success 200 {object} response.Response "{"code": 200, "message": "删除成功"}" // @Router /api/v1/{{.ModuleName}} [delete] // @Security Bearer @@ -194,4 +195,4 @@ func (e {{.ClassName}}) Delete(c *gin.Context) { return } e.OK( req.GetId(), "删除成功") -} \ No newline at end of file +}