-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from zjutjh/dev
init
- Loading branch information
Showing
125 changed files
with
4,714 additions
and
559 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Build | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: 1.22 | ||
|
||
- name: Build | ||
run: | | ||
go install src.techknowlogick.com/xgo@latest | ||
xgo -out 4uonline --targets=*/amd64 . | ||
- name: Archive Output | ||
run: | | ||
mkdir -p artifacts | ||
mv 4uonline* artifacts/ | ||
cp README.md artifacts/ | ||
cp config.example.yaml artifacts/config.yaml | ||
- name: Upload Artifacts | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: build-output | ||
path: artifacts/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Lint | ||
|
||
# 定义触发条件:在 `dev` 分支的 push 或 pull request 事件触发工作流 | ||
on: | ||
push: | ||
branches: | ||
- dev # 当向 dev 分支推送时触发 | ||
pull_request: | ||
branches: | ||
- dev # 当对 dev 分支发起拉取请求时触发 | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest # 指定工作流运行在最新的 Ubuntu 环境中 | ||
|
||
steps: | ||
# 第一步:检查出代码 | ||
- name: Checkout code | ||
uses: actions/checkout@v4 # 使用 GitHub 提供的 checkout 动作,确保代码在工作流环境中可用 | ||
|
||
# 第二步:设置 Go 环境 | ||
- name: Set up Go | ||
uses: actions/setup-go@v5 # 使用 GitHub 提供的 setup-go 动作,设置 Go 环境 | ||
with: | ||
go-version: stable | ||
|
||
# 第三步:运行 golangci-lint | ||
- name: Run golangci-lint | ||
uses: golangci/golangci-lint-action@v6 # 使用 golangci-lint-action | ||
with: | ||
version: v1.62.0 # 指定 golangci-lint 版本 | ||
args: '--config .golangci.yml' # 使用指定的配置文件 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,4 +27,6 @@ go.work.sum | |
config.yaml | ||
|
||
.idea | ||
.vscode | ||
.vscode | ||
|
||
logs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
# 4UOnline-Go | ||
校学生会权益服务系统 | ||
|
||
点此查看[项目说明](docs/README.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,73 @@ | ||
package apiException | ||
|
||
import "net/http" | ||
import ( | ||
"net/http" | ||
|
||
// Error 表示自定义错误,包括状态码、代码和消息。 | ||
"4u-go/app/utils/log" | ||
"github.com/gin-gonic/gin" | ||
"go.uber.org/zap" | ||
) | ||
|
||
// Error 表示自定义错误,包括状态码、消息和日志级别。 | ||
type Error struct { | ||
StatusCode int `json:"-"` | ||
Code int `json:"code"` | ||
Msg string `json:"msg"` | ||
Code int | ||
Msg string | ||
Level log.Level | ||
} | ||
|
||
// Error 表示自定义的错误类型 | ||
var ( | ||
ServerError = NewError(http.StatusInternalServerError, 200500, "系统异常,请稍后重试!") | ||
OpenIDError = NewError(http.StatusInternalServerError, 200500, "系统异常,请稍后重试!") | ||
ParamError = NewError(http.StatusInternalServerError, 200501, "参数错误") | ||
ServerError = NewError(200500, log.LevelError, "系统异常,请稍后重试!") | ||
OpenIDError = NewError(200500, log.LevelInfo, "系统异常,请稍后重试!") | ||
ParamError = NewError(200501, log.LevelInfo, "参数错误") | ||
ReactiveError = NewError(200502, log.LevelInfo, "该通行证已经存在,请重新输入") | ||
UserAlreadyExisted = NewError(200503, log.LevelInfo, "该用户已激活") | ||
RequestError = NewError(200504, log.LevelInfo, "系统异常,请稍后重试!") | ||
StudentNumAndIidError = NewError(200505, log.LevelInfo, "该学号或身份证不存在或者不匹配,请重新输入") | ||
PwdError = NewError(200506, log.LevelInfo, "密码长度必须在6~20位之间") | ||
UserNotFound = NewError(200507, log.LevelInfo, "该用户不存在") | ||
NoThatPasswordOrWrong = NewError(200508, log.LevelInfo, "密码错误") | ||
NotLogin = NewError(200509, log.LevelInfo, "未登录") | ||
NotPermission = NewError(200510, log.LevelInfo, "该用户无权限") | ||
ResourceNotFound = NewError(200511, log.LevelInfo, "访问的资源不存在") | ||
AdminKeyError = NewError(200512, log.LevelInfo, "管理员注册密钥错误") | ||
AdminAlreadyExisted = NewError(200513, log.LevelInfo, "管理员账号已存在") | ||
UploadFileError = NewError(200514, log.LevelInfo, "上传文件失败") | ||
FileSizeExceedError = NewError(200515, log.LevelInfo, "文件大小超限") | ||
FileNotImageError = NewError(200516, log.LevelInfo, "上传的文件不是图片") | ||
|
||
NotInit = NewError(http.StatusNotFound, 200404, http.StatusText(http.StatusNotFound)) | ||
NotFound = NewError(http.StatusNotFound, 200404, http.StatusText(http.StatusNotFound)) | ||
Unknown = NewError(http.StatusInternalServerError, 300500, "系统异常,请稍后重试!") | ||
NotFound = NewError(200404, log.LevelWarn, http.StatusText(http.StatusNotFound)) | ||
) | ||
|
||
// OtherError 返回一个表示其他未定义错误的自定义错误消息 | ||
func OtherError(message string) *Error { | ||
return NewError(http.StatusForbidden, 100403, message) | ||
} | ||
|
||
// Error 方法实现了 error 接口,返回错误的消息内容 | ||
func (e *Error) Error() string { | ||
return e.Msg | ||
} | ||
|
||
// NewError 创建并返回一个新的自定义错误实例 | ||
func NewError(statusCode, code int, msg string) *Error { | ||
func NewError(code int, level log.Level, msg string) *Error { | ||
return &Error{ | ||
StatusCode: statusCode, | ||
Code: code, | ||
Msg: msg, | ||
Code: code, | ||
Msg: msg, | ||
Level: level, | ||
} | ||
} | ||
|
||
// AbortWithException 用于返回自定义错误信息 | ||
func AbortWithException(c *gin.Context, apiError *Error, err error) { | ||
logError(c, apiError, err) | ||
_ = c.AbortWithError(200, apiError) //nolint:errcheck | ||
} | ||
|
||
// logError 记录错误日志 | ||
func logError(c *gin.Context, apiErr *Error, err error) { | ||
// 构建日志字段 | ||
logFields := []zap.Field{ | ||
zap.Int("error_code", apiErr.Code), | ||
zap.String("path", c.Request.URL.Path), | ||
zap.String("method", c.Request.Method), | ||
zap.String("ip", c.ClientIP()), | ||
zap.Error(err), // 记录原始错误信息 | ||
} | ||
log.GetLogFunc(apiErr.Level)(apiErr.Msg, logFields...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package counterName | ||
|
||
// 定义要统计的字段 | ||
|
||
const ( | ||
// QrcodeScan 权益码扫描次数 | ||
QrcodeScan string = "qrcode_scan" | ||
// Feedback 问题反馈数量 | ||
Feedback string = "feedback_scan" | ||
// FeedbackHandle 处理问题反馈数量 | ||
FeedbackHandle string = "feedback_handle" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package feedbackType | ||
|
||
// FeedbackType | ||
const ( | ||
Activities uint = iota // 校园活动 | ||
DiningAndShops // 食堂及商铺 | ||
Dormitories // 宿舍 | ||
Academic // 教学服务(选课、转专业等) | ||
Facilities // 校园设施 | ||
Classrooms // 教室 | ||
Library // 图书馆 | ||
Transportation // 交通 | ||
Security // 安保 | ||
HealthCare // 医疗服务 | ||
Policies // 学院相关政策(如综测等) | ||
Others // 其他服务 | ||
) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.