Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
何 广一
intern_project_backend
Commits
c19129c1
Commit
c19129c1
authored
Jun 24, 2025
by
IronHammer Std
Browse files
readme与示例配置
parent
69760c9b
Changes
6
Show whitespace changes
Inline
Side-by-side
.gitignore
View file @
c19129c1
...
@@ -11,8 +11,9 @@
...
@@ -11,8 +11,9 @@
# Output of the go coverage tool, specifically when used with LiteIDE
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
*.out
#
Databa
se files
#
U
se
r
files
*.db
*.db
*.json
# Dependency directories (remove the comment below to include it)
# Dependency directories (remove the comment below to include it)
# vendor/
# vendor/
...
@@ -20,3 +21,9 @@
...
@@ -20,3 +21,9 @@
.idea/
.idea/
.vscode/
.vscode/
log/
log/
# except Example directory
# Do not ignore Example directory
# Do not ignore files in Example directory
!Example/
!Example/**
\ No newline at end of file
Config.json
View file @
c19129c1
{
{
"serverPort"
:
"
:
8080"
,
"serverPort"
:
"8080"
,
"dbPath"
:
"comments.db"
"dbPath"
:
"comments.db"
}
}
\ No newline at end of file
Server.go
View file @
c19129c1
...
@@ -202,8 +202,8 @@ func initServer(serverPort string) {
...
@@ -202,8 +202,8 @@ func initServer(serverPort string) {
http
.
HandleFunc
(
"/comment/delete"
,
deleteCommentHandler
)
http
.
HandleFunc
(
"/comment/delete"
,
deleteCommentHandler
)
// 启动服务器
// 启动服务器
log
.
Println
(
"Server starting on http://localhost"
+
serverPort
)
log
.
Println
(
"Server starting on http://localhost
:
"
+
serverPort
)
if
err
:=
http
.
ListenAndServe
(
serverPort
,
nil
);
err
!=
nil
{
if
err
:=
http
.
ListenAndServe
(
":"
+
serverPort
,
nil
);
err
!=
nil
{
log
.
Fatal
(
"Server failed to start: "
,
err
)
log
.
Fatal
(
"Server failed to start: "
,
err
)
}
}
}
}
\ No newline at end of file
example/Config.json
0 → 100644
View file @
c19129c1
{
"serverPort"
:
"8080"
,
"dbPath"
:
"example.db"
}
\ No newline at end of file
example/example.db
0 → 100644
View file @
c19129c1
readme.md
View file @
c19129c1
# INTERN PROJECT BACKEND
## 后端生成方式
## 参数配置与启动
设生成好的exe文件为BackEnd.exe。
参数配置在BackEnd.exe同目录的Config.json当中配置;
仓库里面给出了示例Config.json。
json的内容:
```
json
{
"serverPort"
:
"8080"
,
"dbPath"
:
"example.db"
}
```
8080是前端监听的端口;
example.db是存储评论的数据库。
Config.json和example.db在仓库的Example目录下。
示例的db文件是空的。
使用时请将两个文件放在编译好的exe同目录下,启动BackEnd.exe来启动后端。
## 前端对接
前端对接部分与接口文档一致。具体内容如下:
设后端正确配置后,在8080端口上打开了后端服务(http://localhost:8080)。
### 获取评论:
URL:
部分获取: http://localhost:8080/comment/get?page={待请求的页码,从1开始计数}&size={每页大小}
获取全部: http://localhost:8080/comment/get?size=-1
方法:GET
header:无需
body: 无需
后端返回的response:
```
json
{
"code"
:
0
,
//
0
表示成功,其他表示失败
"msg"
:
"success"
,
//
返回信息
"data"
:
{
"total"
:
int
,
//评论的总数,无论请求参数是什么
"comments"
:
[
{
"id"
:
int
,
//
评论ID
"name"
:
"string"
,
//
评论者名字
"content"
:
"string"
,
//
评论内容
}
]
}
}
```
### 添加评论:
URL: http://localhost:8080/comment/add
方法:POST
header:
```
json
{
"Content-Type"
:
"application/json"
}
```
body:
```
json
{
"name"
:
"string"
,
//
评论者名字
"content"
:
"string"
//
评论内容
}
```
后端返回的response:
```
json
{
"code"
:
0
,
//
0
表示成功,其他表示失败
"msg"
:
"success"
,
//
返回信息
"data"
:
{
"id"
:
int
,
//
评论ID
"name"
:
"string"
,
//
评论者名字
"content"
:
"string"
//
评论内容
}
}
```
### 删除评论:
URL: http://localhost:8080/comment/delete?id={待删除的评论id}
方法:POST
header:无需
body: 无需
后端返回的response:
```
json
{
"code"
:
0
,
//
0
表示成功,其他表示失败
"msg"
:
"success"
,
//
返回信息
"data"
:
null
}
```
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment