Merge branch 'master' of http://git.hanxiaonuan.cn:3000/zhangchao/go_blog
This commit is contained in:
15
.gitea/Dockerfile
Normal file
15
.gitea/Dockerfile
Normal file
@@ -0,0 +1,15 @@
|
||||
FROM golang:alpine AS builder
|
||||
|
||||
WORKDIR /build
|
||||
|
||||
ADD go.mod .
|
||||
COPY . .
|
||||
RUN go build
|
||||
|
||||
|
||||
FROM alpine
|
||||
|
||||
WORKDIR /build
|
||||
COPY --from=builder /build/hello /build/hello
|
||||
|
||||
CMD ["./go_blog"]
|
||||
21
.gitea/workflows/demo.yaml
Normal file
21
.gitea/workflows/demo.yaml
Normal file
@@ -0,0 +1,21 @@
|
||||
name: Gitea Actions Demo
|
||||
run-name: ${{ gitea.actor }} is testing out Gitea Actions
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
container-job:
|
||||
name: my first job test
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: golang:latest
|
||||
env:
|
||||
GO111MODULE: on
|
||||
GOPROXY: https://goproxy.cn,direct
|
||||
ports:
|
||||
- 8080
|
||||
volumes:
|
||||
- /data:/data
|
||||
|
||||
steps:
|
||||
- name: Check for dockerenv file1
|
||||
run: (ls /.dockerenv && echo Found dockerenv) || (echo No dockerenv)
|
||||
25
.gitea/workflows/go.yaml
Normal file
25
.gitea/workflows/go.yaml
Normal file
@@ -0,0 +1,25 @@
|
||||
name: Go build
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
docker:
|
||||
name: build and run
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: https://gitea.com/actions/checkout@v4
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: https://gitea.com/docker/setup-buildx-action@v3
|
||||
|
||||
- name: Build Docker image
|
||||
run: |
|
||||
docker build -t your-image-name:latest -f ./Dockerfile .
|
||||
|
||||
- name: Run Docker container
|
||||
run: |
|
||||
docker run -d -p 8080:8080 your-image-name:latest
|
||||
36
Dockerfile
Normal file
36
Dockerfile
Normal file
@@ -0,0 +1,36 @@
|
||||
# 使用官方的 Go 运行时作为基础镜像
|
||||
FROM golang:latest AS builder
|
||||
ENV GO111MODULE=on \
|
||||
CGO_ENABLED=0 \
|
||||
GOOS=linux \
|
||||
GOARCH=amd64 \
|
||||
GOPROXY=https://goproxy.cn,direct
|
||||
# 设置工作目录
|
||||
WORKDIR /app
|
||||
|
||||
# 将当前目录下的所有文件复制到工作目录中
|
||||
COPY . .
|
||||
|
||||
# 构建可执行文件
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -v -o app .
|
||||
|
||||
|
||||
# 使用一个更小的基础镜像来减小最终镜像的大小
|
||||
FROM alpine:latest
|
||||
# 时区设置成当前时区
|
||||
RUN apk add --no-cache tzdata
|
||||
ENV TZ="Asia/Shanghai"
|
||||
# 设置工作目录
|
||||
WORKDIR /root/
|
||||
# 从构建阶段复制可执行文件
|
||||
COPY --from=builder /app/app .
|
||||
# 在容器目录 /root/ 创建一个目录 为config
|
||||
RUN mkdir conf .
|
||||
COPY --from=builder /app/conf/ ./conf/
|
||||
COPY --from=builder /app/templates/ ./templates/
|
||||
|
||||
# 暴露端口
|
||||
EXPOSE 8080
|
||||
|
||||
# 运行可执行文件
|
||||
CMD ["./app"]
|
||||
@@ -1,9 +1,9 @@
|
||||
[mysql]
|
||||
Type = mysql
|
||||
Host = 127.0.0.1
|
||||
Host = 47.93.160.42
|
||||
Port = 3306
|
||||
User = root
|
||||
Password = root
|
||||
User = blog
|
||||
Password = qI7=bL4@iJ
|
||||
DBName = blog
|
||||
Charset = utf8mb4
|
||||
Prefix = gin_
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
mysql:
|
||||
database:
|
||||
Type: mysql
|
||||
Host: 127.0.0.1
|
||||
Port: 3306
|
||||
User: root
|
||||
Password: root
|
||||
User: blog
|
||||
Password: qI7=bL4@iJ
|
||||
DBName: blog
|
||||
Charset: utf8mb4
|
||||
Prefix: gin_
|
||||
|
||||
@@ -16,7 +16,7 @@ func CreateContentHandler(ctx *gin.Context) {
|
||||
}
|
||||
|
||||
if err := models.DB.Create(&content).Error; err != nil {
|
||||
ctx.JSON(500, gin.H{"error": "Failed to create content"})
|
||||
ctx.JSON(500, gin.H{"error": "增加内容失败"})
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
4
go.sum
4
go.sum
@@ -7,8 +7,6 @@ github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583j
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
|
||||
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
|
||||
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
|
||||
@@ -31,6 +29,8 @@ github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ
|
||||
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
|
||||
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
|
||||
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
||||
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
|
||||
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
|
||||
|
||||
4
main.go
4
main.go
@@ -37,8 +37,12 @@ func init() {
|
||||
flag.BoolVar(&isOrmDebug, "orm", true, "是否开启gorm的debug信息")
|
||||
flag.Parse()
|
||||
|
||||
<<<<<<< HEAD
|
||||
//conf.SetUp()
|
||||
conf.SetUp1()
|
||||
=======
|
||||
conf.SetUp()
|
||||
>>>>>>> c628419559368f0270c2573d91a06a1a9531d53a
|
||||
models.SetUp(isOrmDebug)
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ import (
|
||||
"go_blog/models"
|
||||
"time"
|
||||
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/golang-jwt/jwt"
|
||||
)
|
||||
|
||||
// 定义jwt载荷
|
||||
|
||||
Reference in New Issue
Block a user