1 Star 0 Fork 0

Andy / QQHXshop

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

wxcloudrun-golang

GitHub license GitHub package.json dependency version (prod)

微信云托管 golang 模版,实现简单的计数器读写接口,使用云托管 MySQL 读写、记录计数值。

快速开始

前往 微信云托管快速开始页面,选择相应语言的模板,根据引导完成部署。

目录结构说明

.
├── Dockerfile                Dockerfile 文件
├── LICENSE                   LICENSE 文件
├── README.md                 README 文件
├── container.config.json     微信云托管流水线配置
├── db                        数据库逻辑目录
├── go.mod                    go.mod 文件
├── go.sum                    go.sum 文件
├── index.html                主页 html 
├── main.go                   主函数入口
└── service                   接口服务逻辑目录

服务 API 文档

GET /api/count

获取当前计数

请求参数

响应结果

  • code:错误码
  • data:当前计数值
响应结果示例
{
  "code": 0,
  "data": 42
}

调用示例

curl https://<云托管服务域名>/api/count

POST /api/count

更新计数,自增或者清零

请求参数

  • actionstring 类型,枚举值
    • 等于 "inc" 时,表示计数加一
    • 等于 "clear" 时,表示计数重置(清零)
请求参数示例
{
  "action": "inc"
}

响应结果

  • code:错误码
  • data:当前计数值
响应结果示例
{
  "code": 0,
  "data": 42
}

调用示例

curl -X POST -H 'content-type: application/json' -d '{"action": "inc"}' https://<云托管服务域名>/api/count

使用注意

如果不是通过微信云托管控制台部署模板代码,而是自行复制/下载模板代码后,手动新建一个服务并部署,需要在「服务设置」中补全以下环境变量,才可正常使用,否则会引发无法连接数据库,进而导致部署失败。

  • MYSQL_ADDRESS
  • MYSQL_PASSWORD
  • MYSQL_USERNAME 以上三个变量的值请按实际情况填写。如果使用云托管内MySQL,可以在控制台MySQL页面获取相关信息。

License

MIT

MIT License Copyright (c) 2021 Tencent Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

暂无描述 展开 收起
Go 等 3 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/AppleOfEyes/QQHXshop.git
git@gitee.com:AppleOfEyes/QQHXshop.git
AppleOfEyes
QQHXshop
QQHXshop
master

搜索帮助