测试
$ go get github.com/julienschmidt/httprouter $ go get github.com/garyburd/redigo/redis $ cd blog $ go build $ ./blog
这里创建一个简单的博客系统,具有以下功能:
http://localhost/ 显示欢迎消息, http://localhost/posts 显示所有posts http://localhost/posts/id 根据id显示post
推送测试
for i in {1..9999} ;do \ curl -H "Content-Type: application/json" -d '{"topic": "Hello from Mars","text": "I am anonymous hehe. Catch me if you can." }' \ http://localhost:8080/posts; done
总结
第一个是返回响应报文内容,第二个是请求报文中的内容,第三个是url后面的参数
func PostDelete(w http.ResponseWriter, r *http.Request, ps mux.Params)
–
127.0.0.1:6379> del key key (integer) 1 127.0.0.1:6379> del key key (integer) 0
按照上面的执行结果,应该是返回内容中的数字部分是否为1的意思
reply, err := c.Do("DEL", "post:"+strconv.Itoa(id)) HandleError(err) if reply.(int) != 1 { fmt.Println("No post removed") } else { fmt.Println("Post removed") }
–
gitlab文件:https://git.andblog.cn/root/go_rest/tree/master
参考博客:https://medium.com/code-zen/rest-apis-server-in-go-and-redis-66e9cb80a71b
参考博客:http://blog.csdn.net/wangshubo1989/article/details/77163336
使用了httproute模块,redis操作模块
–
–
–
评论前必须登录!
注册