hexo+github+hexo-theam-next个人博客
apidoc详解
ApiDoc使用详解
参考项目文档:apidoc官方文档
1. 安装apidoc
注意:首先要安装
npm
网上搜索
安装命令:npm install apidoc -g
2.安装grunt modulenpm install grunt-apidoc --save-dev
3.配置apidoc.json或者package.json文件
1 | { |
4.apidoc接口文档参数详解
@api {method} /path/to/:uid [title]
注:定义接口名,请求方式,路径(必填,除了apiDefine)
1
2
3/**
* @api {post} /user/reg 用户注册
*/@apiDefine name [title]
注:定义公共文档块,可使用apiUse在其他文档中插入
1
2
3
4
5
6
7
8
9/**
* @apiDefine MyError
* @apiError UserNotFound The <code>id</code> of the User was not found.
*/
/**
* @api {get} /user/:id
* @apiUse MyError
*/@apiDescription text
注:接口描述
1
2
3/**
*@apiDescription 用户登录接口
*/@apiName name
注:接口名(必填,用户文档左侧菜单二级分类)
1
2
3/**
*@apiName login
*/@apiGroup group
注:接口分组(必填,用户文档左侧菜单一级分类)
1
2
3/**
*@apiGroup user
*/@apiVersion 1.1.1
注:接口版本号(必须是:major.minor.patch格式:1.0.0)
1
2
3/**
*@apiVersion 1.0.0
*/@apiDeprecated text
注:未测试
1
2
3/**
*@apiDeprecated text
*/@apiIgnore [hint]
注:忽略的接口[hint]为忽略的原因,可选
1
2
3/**
*@apiIgnore hint
*/@apiPermission name
注:api的权限名
1
2
3/**
*@apiPermission admin
*/@apiParam [(group)] [{type}] [field=defaultValue] [description]
注:接口参数
{type}包括:{String} 字符串,{Boolean}布尔值, {Number}数字, {Object}对象, {String[]}字符串数组
[field] 可选参数field
field 必选参数 field
=’string’ 参数默认值
{type{size}} 代表字符长度{String{6-12}}
[description] 字段描述1
2
3
4
5
6
7
8
9
10
11/**
* @api {post} /user/
* @apiParam {String} [firstname] Optional Firstname of the User.
* @apiParam {String} lastname Mandatory Lastname.
* @apiParam {String} country="DE" Mandatory with default value "DE".
* @apiParam {Number} [age=18] Optional Age with default 18.
*
* @apiParam (Login) {String} pass Only logged in users can post this.
* In generated documentation a separate
* "Login" Block will be generated.
*/@apiSuccess [(group)] [{type}] field [description]
注:接口返回值显示
{type}包括:{String} 字符串,{Boolean}布尔值, {Number}数字, {Object}对象, {String[]}字符串数组
field 返回字段名
[description] 字段描述1
2
3
4
5/**
* @api {get} /user/:id
* @apiSuccess (200) {String} firstname Firstname of the User.
* @apiSuccess (200) {String} lastname Lastname of the User.
*/@apiSuccessExample [{type}] [title] example
注:接口返回值显示
{type}包括:{json}
title 返回说明:
[example] 返回例子1
2
3
4
5
6
7
8
9/**
* @api {get} /user/:id
* @apiSuccessExample {json} Success-Response:
* HTTP/1.1 200 OK
* {
* "firstname": "John",
* "lastname": "Doe"
* }
*/
5.版本比较
要保留两份,后新的版本的时候。保留原来的版本说明,复制修改为新的版本,另外修改新的版本号
1 | /** |
mysql用户远程登录
array_merge() 函数详解
go操作mysql数据库
go操作mysql数据库
示例数据库结构
数据库test,用户表userinfo,关联用户信息表userdetail
1 | CREATE TABLE `userinfo` ( |
操作数据库
1 引入库文件
1 | import ( |
2 连接数据库
1 | //host 数据库地址 |
3 插入数据
1 | //插入语句预处理 |
4 查询数据
1 | //获取数据库的所有字段 |
5 修改数据
1 | stmt,_ := db.Prepare("update userinfo set username=? where id = ?") |
6 删除数据
1 | stmt,_ := db.Prepare("Delete from userinfo where uid=?") |
go语言学习之并发
go 并发
goroutine
- goroutine是Go并行设计的核心。goroutine说到底其实就是协程,但是它比线程更小
- Go语言内部帮你实现了这些goroutine之间的内存共享
- 执行goroutine只需极少的栈内存(大概是4~5KB),当然会根据相应的数据伸缩。也正因为如此,可同时运行成千上万个并发任务
- goroutine比thread更易用、更高效、更轻便
- goroutine是通过Go的runtime管理的一个线程管理器。goroutine通过go关键字实现了,其实就是一个普通的函数。
1
go hello(a,b,c)
channels
定义一个channel时,也需要定义发送到channel的值的类型,
注意:必须使用make 创建channel
channel通过操作符<-来接收和发送数据
1 | var c = make(chan int) |
默认情况下,channel接收和发送数据都是阻塞的
buffered channels (带缓冲的channels)
1 | ch := make(chan type,value) |
注意:
- range (使用range方法读取channels里面的数据)
- close() 关闭channel,应该在生产者
1 | package main |
select (switch切换channel)
select默认是阻塞的,只有当监听的channel中有发送或接收可以进行时才会运行,当多个channel都准备好的时候,select是随机的选择一个执行的。
1 | package main |
select设置超时
1 | func main() { |
runtime gotoutine
runtime包中有几个处理goroutine的函数:
- Goexit
退出当前执行的goroutine,但是defer函数还会继续调用
- Gosched
让出当前goroutine的执行权限,调度器安排其他等待的任务运行,并在下次某个时候从该位置恢复执行。
- NumCPU
返回 CPU 核数量
- NumGoroutine
返回正在执行和排队的任务总数
- GOMAXPROCS
用来设置可以并行计算的CPU核数的最大值,并返回之前的值。