-
Notifications
You must be signed in to change notification settings - Fork 3
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 #2 from cbluebird/main
add backend
- Loading branch information
Showing
3 changed files
with
105 additions
and
1 deletion.
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
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 @@ | ||
# 运行微精弘程序 | ||
|
||
## 配置 | ||
|
||
在项目根目录下新建`config.yaml`,配置每个项目对应的yaml文件 | ||
|
||
## 如何开始 | ||
|
||
在项目根目录下执行 | ||
|
||
```bash | ||
go build -o 项目名 | ||
``` | ||
|
||
然后直接运行编辑出来的程序就行了 | ||
|
||
## Docker部署 |
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,73 @@ | ||
# 微精弘后端文档 | ||
|
||
## 风格规范说明 | ||
|
||
- 所有的文件/文件夹名采用小驼峰命名(首单词全小写,后面的单词首字母大写) | ||
- 代码采用tab制表符缩进而不是空格(Go 的默认风格)tab默认四空格。 | ||
|
||
## 配置系统说明 | ||
|
||
采用了viper这个配置文件库,方便读取配置信息。 | ||
|
||
## 项目结构 | ||
|
||
微精弘后端主要的技术栈是Go语言和Rust语言,其中的WeJH-GO、User-Center、funnel使用的Go语言,yxy使用的是Rust语言编写。 | ||
|
||
微精弘后端使用了微服务架构思想,将不同的功能拆分成不同的模块,由WeJH-Go去调用不同的服务。 | ||
|
||
**WeJH-Go与各个模块之间的通讯采用HTTP协议** | ||
|
||
微精弘的具体项目结构如下所示: | ||
``` | ||
微精弘后端 | ||
├── WeJH-Go | ||
│ ├── funnel | ||
│ ├── yxy | ||
│ ├── User-Center | ||
``` | ||
|
||
各个模块的详细说明如下: | ||
|
||
- WeJH-Go:核心部分,通过该模块去调用其他模块的服务,前端的所有请求都会打到该模块上,并作出相应的处理和相应 | ||
- funnel:处理与正方教务系统、图书馆、餐厅相应的逻辑。 | ||
- yxy:处理与容大后勤相关的服务,容大后勤的服务主要在易校园app上可以查询,yxy主要是爬取易校园app的相关数据,返回给WeJH-Go | ||
- User-Center: 处理用户登陆与注册,之后的精弘产品,都可以通过用户中心做统一身份验证 | ||
|
||
各个模块的相应代码均在zjutjh的Github仓库开源。 | ||
|
||
## 微信小程序的一些说明 | ||
|
||
### 登陆 | ||
|
||
在整个小程序中,最关键的就是openid,这个 openid 是微信小程序 用来标识用户的(可以理解成一个贼NB的用户名) | ||
|
||
登陆的时候,前端返回给我们一个code,我们根据code去对微信服务器发送请求从而得到一个openid,每个微信用户的openid唯一,我们根据openid来实现鉴权 | ||
|
||
在测试的时候请注意,这个code只有使用微信小程序的前端生成才是有效的,我们在apifox测试会得到code无效的报错 | ||
|
||
### 同源策略问题 | ||
|
||
小程序在容器里面运行,不是单纯的浏览器,小程序的请求不是浏览器发的,是容器发的,所以就不存在跨域问题。如果有新的域名要请求,要把域名加到开发者平台白名单里面,容器发请求之前会对域名校验,不在白名单的发不出去。 | ||
|
||
## WeJH-Go后端程序代码结构及相关说明 | ||
``` | ||
WeJH-Go | ||
├── app | ||
│ ├── apiException //统一错误处理 | ||
│ ├── config //小程序基础配置设置,比如学期时间等等 | ||
│ ├── controllers //控制器,主要包括了处理函数 | ||
│ ├── midwares //中间件 | ||
│ ├── models //数据库表 | ||
│ ├── services //核心服务 | ||
│ └── utils //一些封装好的工具 | ||
│ ├── fetch //发送HTTP请求的工具 | ||
│ └── stateCode | ||
├── config //主要包括小程序后端配置文件,使用viper | ||
│ ├── api //其他服务的api地址 | ||
│ ├── config | ||
│ ├── database | ||
│ ├── redis | ||
│ ├── router | ||
│ ├── session | ||
``` |