dataserver test code
main.go
package main import (
"database/sql"
"fmt"
"log"
"net/http"
"time" _ "github.com/go-sql-driver/mysql"
) func main() {
http.HandleFunc("/getuser", getuser)
s := &http.Server{
Addr: ":92",
ReadTimeout: * time.Second,
WriteTimeout: * time.Second,
MaxHeaderBytes: << ,
}
log.Fatal(s.ListenAndServe())
} func getuser(w http.ResponseWriter, r *http.Request) { w.Write([]byte(getuser_json()))
} func getuser_json() string {
db, err := sql.Open("mysql", "root:root@tcp(localhost:3306)/dataserver2?charset=utf8")
if err != nil {
panic(err.Error())
}
defer db.Close()
zsql := fmt.Sprintf("insert into test(title) values('92:%v')", GetGuid())
_, err = db.Query(zsql)
if err != nil {
panic(err.Error())
} if err != nil {
return err.Error()
} else {
return "ok"
} }
guid.go
package main import (
"crypto/md5"
"crypto/rand"
"encoding/base64"
"encoding/hex"
"io"
) func GetMd5String(s string) string {
h := md5.New()
h.Write([]byte(s))
return hex.EncodeToString(h.Sum(nil))
} func GetGuid() string {
b := make([]byte, ) if _, err := io.ReadFull(rand.Reader, b); err != nil {
return ""
}
return GetMd5String(base64.URLEncoding.EncodeToString(b))
}
dataserver test code的更多相关文章
- Visual Studio Code 代理设置
Visual Studio Code (简称 VS Code)是由微软研发的一款免费.开源的跨平台文本(代码)编辑器,在十多年的编程经历中,我使用过非常多的的代码编辑器(包括 IDE),例如 Fron ...
- 我们是怎么做Code Review的
前几天看了<Code Review 程序员的寄望与哀伤>,想到我们团队开展Code Review也有2年了,结果还算比较满意,有些经验应该可以和大家一起分享.探讨.我们为什么要推行Code ...
- Code Review 程序员的寄望与哀伤
一个程序员,他写完了代码,在测试环境通过了测试,然后他把它发布到了线上生产环境,但很快就发现在生产环境上出了问题,有潜在的 bug. 事后分析,是生产环境的一些微妙差异,使得这种 bug 场景在线下测 ...
- 从Script到Code Blocks、Code Behind到MVC、MVP、MVVM
刚过去的周五(3-14)例行地主持了技术会议,主题正好是<UI层的设计模式——从Script.Code Behind到MVC.MVP.MVVM>,是前一天晚上才定的,中午花了半小时准备了下 ...
- 在Visual Studio Code中配置GO开发环境
一.GO语言安装 详情查看:GO语言下载.安装.配置 二.GoLang插件介绍 对于Visual Studio Code开发工具,有一款优秀的GoLang插件,它的主页为:https://github ...
- 代码的坏味道(14)——重复代码(Duplicate Code)
坏味道--重复代码(Duplicate Code) 重复代码堪称为代码坏味道之首.消除重复代码总是有利无害的. 特征 两个代码片段看上去几乎一样. 问题原因 重复代码通常发生在多个程序员同时在同一程序 ...
- http status code
属于转载 http status code:200:成功,服务器已成功处理了请求,通常这表示服务器提供了请求的网页 404:未找到,服务器未找到 201-206都表示服务器成功处理了请求的状态代码,说 ...
- Visual Studio Code——Angular2 Hello World 之 2.0
最近看到一篇用Visual Studio Code开发Angular2的文章,也是一篇入门教程,地址为:使用Visual Studio Code開發Angular 2專案.这里按部就班的做了一遍,感觉 ...
- WebStorm 2016 最新版激活(activation code方式)
WebStorm 2016 最新版激活(activation code方式) WebStorm activation code WebStorm 最新版本激活方式: 今天下载最新版本的WebStorm ...
随机推荐
- Extjs 图片的自动缩放
function resizeImage(obj) { var width = Ext.getCmp('welcome').getWidth(); //welcome 为一Panel的id 分割线下的 ...
- Linux modules install
安装模块的时候出现错误:modprobe: chdir(3.0.35-g6774ed9-dirty): No such file or directory. 内核模块没有安装正确.本文记录解决方法. ...
- MVC 发布
发布为局域网可用:以IP地址访问 安装IIS 发布 出现的错误: 处理程序"BlockViewHandler"在其模块列表中有一个错误模块"ManagedPipeline ...
- AngularJS Best Practices: pretty urls
By default, AngularJS will route URLs with a hashtag. For example: http://example.com/ http://exampl ...
- CentOS 命令模式下设置静态IP
ASP.NET程序猿第一次修改IP,之前没有接触过Linux,有点伤不起... # cd /etc/sysconfig/network-scripts/ # ls 会看到 ifcfg-eth0 if ...
- ligerui_ligerTree_006_ligerui事件支持
ligerui:ligerTree事件支持: 源码地址:http://download.csdn.net/detail/poiuy1991719/8571255 效果图: 代码:json.txt [ ...
- PowerDesigner15.1给自定义架构表字段添加MS_Description出错
原因:系统函数sp_addextendedproperty 的第3个参数(用户名) 应该是Schema.但PD在生成的时候却是’user’ 解决方法 在PDM时.DataBase >> E ...
- MVC(二)
所谓EF延迟加载,就是使用Lamabda或Linq查询数据时,EF并不会将数据直接查询出来,而是在用到的这个查询结果的时候才会加载到内存中.延迟加载也可以理解成 按需加载,顾名思义,就是按照所需的数据 ...
- 设置Ubuntu 14.04右键终端的方法
设置Ubuntu 14.04右键终端的方法如下: 首先要安装一个包,即可在右键里面添加一个"打开终端"的菜单. sudo apt-get install nautilus-open ...
- xcode编译错误
1.xcode无效文件的编译错误. 问题: clang: error: no such file or directory: '/Users/admin/client/trunk/sengoku_sc ...