这是我参与「第五届青训营 」伴学笔记创作活动的第 9 天
获取源码
首先创建源码的目录,可以是%GOPATH%/src/github.com获取simple-demo的源码
mkdir %GOPATH%/src/github.com
cd %GOPATH%/src/github.com
git clone https://github.com/RaymondCode/simple-demo.git
启动服务
进入代码项目的路径下,编译go代码,并运行程序
go build
.\simple-demo.exe
然后应该会看到如下输出,说明运行成功。根据打印的日志可以看到,此时服务运行于8080端口。
[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.
[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production. using env: export GIN_MODE=release
[GIN-debug] POST /douyin/relation/action/ --> github.com/RaymondCode/simple-demo/controller.RelationAction (3 handlers)
[GIN-debug] GET /douyin/relation/follow/list/ --> github.com/RaymondCode/simple-demo/controller.FollowList (3 handlers)
[GIN-debug] GET /douyin/relation/follower/list/ --> github.com/RaymondCode/simple-demo/controller.FollowerList (3 handlers)
[GIN-debug] GET /douyin/relation/friend/list/ --> github.com/RaymondCode/simple-demo/controller.FriendList (3 handlers)
[GIN-debug] GET /douyin/message/chat/ --> github.com/RaymondCode/simple-demo/controller.MessageChat (3 handlers)
[GIN-debug] POST /douyin/message/action/ --> github.com/RaymondCode/simple-demo/controller.MessageAction (3 handlers)
[GIN-debug] [WARNING] You trusted all proxies, this is NOT safe. We recommend you to set a value.
Please check pkg.go.dev/github.com/… for details.
[GIN-debug] Environment variable PORT is undefined. Using port :8080 by default
[GIN-debug] Listening and serving HTTP on :8080
安装抖声app
极简抖音App使用说明 - 青训营版 - 飞书云文档 (feishu.cn)
参考上述文档,下载抖声app。
在windows环境下,无法直接运行安卓系统的程序,因此需要使用安卓模拟器来进行安装和调试。
本文以夜神模拟器为例,介绍如何在windows系统上安装apk。首先到夜神模拟器官网下载并安装模拟器:夜神安卓模拟器-安卓模拟器电脑版下载_安卓手游模拟器_手机模拟器_官网 (yeshen.com)
安装完成并打开之后,可以点击工具栏中的“安装apk”按钮,选择刚才下载的抖声app(即app-release.apk)进行安装。或者也可以直接在文件系统中把需要安装的apk拖拽到夜神模拟器中进行安装即可,安装完成之后如下图所示。
配置ip地址
安装完抖声之后,直接运行发现连不上网,原因是ip配置错误。双击右下角的“我”按钮,可以进入ip配置页面,如下所示。
在这个页面需要根据本地的ip地址进行重新的配置,如何获取当前windows系统的ip呢?可以在命令行下使用ipconfig命令,即可得到当前系统中各网卡的ip地址了,如下图所示。
把ip地址填入app中的BaseUrl,注意要拼接上端口号8080(因为之前运行代码时打印的日志显示服务运行在8080端口),之后点击保存并重启,然后就可以在首页看到视频了!如下图所示:
后端服务打印的日志如下,说明收到了HTTP请求