Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finish!!!!! #25

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Haderacher/HDU-QA-Platform/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 忽略版本控制文件
.git
.gitignore
16 changes: 16 additions & 0 deletions Haderacher/HDU-QA-Platform/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
*.xml
*.iml
# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/
35 changes: 35 additions & 0 deletions Haderacher/HDU-QA-Platform/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Use the official Golang image as the base image
FROM golang:1.23-alpine AS builder

# Set the Current Working Directory inside the container
WORKDIR /app

# Copy go.mod and go.sum files
COPY go.mod go.sum ./

# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed
RUN go mod download

# Copy the source from the current directory to the Working Directory inside the container
COPY . .

# Build the Go app
RUN go build -o main ./cmd/main.go

# Start a new stage from scratch
FROM alpine:latest

# Set the Current Working Directory inside the container
WORKDIR /app

# Copy the Pre-built binary file from the previous stage
COPY --from=builder /app/main /app/main

# Copy the configuration files
COPY --from=builder /app/conf /app/conf

# Expose port 8082 to the outside world
EXPOSE 8082

# Command to run the executable
ENTRYPOINT ["/app/main"]
45 changes: 45 additions & 0 deletions Haderacher/HDU-QA-Platform/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# 介绍

这是以github上的一个开源框架为基础,并借助了ai的帮助,由我开发的用户管理系统+问答系统。

本项目支持docker部署!

## 用户管理系统
实现了基于session会话机制的用户登录系统。注册时在mysql中存放用户名和密码。
以后每次登录,服务端都会保存一个最新session会话存放于redis缓存,同时客户端保存为cookie,这个session有过期时间。以后每次登录,都会更新这个session。

实现了用于对请求进行身份验证的中间件函数`AuthMiddleWare`,在使用本系统的其他所有服务,如用户信息请求,访问问答系统时,都需要经过这个中间件进行
鉴权,鉴权成功才能访问。

实现了用户登出功能。当客户端请求登出,会在服务端删除redis中的session,这样客户端的cookie就失效了,需要重新登录。

## 问答系统
没什么好说的,都是对问题和回答的增删改查

## 数据库设计
### mysql负责存放三张表:
1. 用户(users):存放用户信息和密码
- 主键:用户id
2. 问题(questions):存放问题
- 主键:回答id
- 外键:用户id、
3. 回答(answers):存放回答
- 主键:回答id
- 外键:问题id、用户id

即问题与回答之间是一对多的关系
问题与用户、回答与用户是一对一的关系

![img.png](doc/img/img.png)


## 系统架构设计/设计模式
1. 采用了分层解耦的思想。采用传统web开发的分层架构,主要分为controller、service、dao三层。使得代码功能之间的耦合度减小,每一层代码只服务于
特定的功能,增加了代码的可维护性。
2. 实现了基于session会话机制的用户登录系统。用户不用每次都输入密码,且redis读写速度快。优化了用户体验。
3. 实现了单例设计模式。将所有的配置信息都放在配置文件中,通过`sync.Once`来保证并发安全,同时确保配置信息、数据库连接只会被初始化一次。
4. 介入了llama ai,用flask框架写了一个服务器,与本项目之间通过restfulapi通信。


## 带改进
1. 没有体现依赖注入的思想
Loading