ginblog

command module
v0.0.0-...-8596441 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2024 License: MIT Imports: 3 Imported by: 0

README

ginblog

MIT 许可证 GitHub stars Gitee stars Go

介绍

个人博客系统

目录结构
软件架构
  1. 前端(frontend)

  2. 后端(backend)

  3. 数据库

安装教程
克隆仓库
git clone https://gitee.com/chyshen/ginblog.git
# or
git clone https://github.com/chyshen/ginblog.git
前端(frontend)
  1. 安装
cd /ginblog/web
pnpm init
  1. 运行
pnpm dev
后端(backend)
  1. 安装
cd /ginblog/api
go mod tidy
  1. 运行
go run .
Docker部署

以Ubuntu为例

卸载旧版本
for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do apt-get remove $pkg; done
安装依赖
apt-get update
apt-get install ca-certificates curl gnupg
添加GPG公钥
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
  tee /etc/apt/sources.list.d/docker.list > /dev/null
安装docker
apt-get update
apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
编写Dockerfile

dockerfile参考文档:https://www.jb51.net/server/293884fmf.htm

# 使用官方Go镜像作为构建环境
FROM golang:latest
RUN go env -w GO111MODULE=on
RUN go env -w GOPROXY=https://goproxy.cn,https://goproxy.io,direct

# 设置工作目录
WORKDIR /app

# 复制go.mod和go.sum文件,以确保依赖关系一致性
COPY go.mod go.sum ./
# 获取依赖项
RUN go mod download

# 复制项目源代码
COPY . /app

# 构建项目
RUN go build .

EXPOSE 3000

ENTRYPOINT ["./ginblog"]
配置ginblog的config

host: ginblog-mysql 是为了后面容器互通做准备,对应的是mysql容器的name

mysql:
  host: ginblog-mysql
  port: 3306
  user: ginblog
  password: 123456
  dbname: ginblog
前端web文件夹下axios请求地址,前端推荐使用Nginx部署
axios.defaults.baseURL = 'http://localhost:3000/api/v1'

# 改为

axios.defaults.baseURL = 'http://线上服务器ip或域名:3000/api/v1'

修改地址后,重新打包

pnpm run build
生成镜像

生成ginblog docker image

docker build -t ginblog .
docker run -d -p 3000:3000 --name ginblog ginblog
使用说明
  1. xxxx
  2. xxxx
  3. xxxx

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
api
v1
Package docs Code generated by swaggo/swag.
Package docs Code generated by swaggo/swag.
tests
api

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL