http://blog.csdn.net/fyxichen/article/details/50991805
Submitted by admin on 2017, June 12, 9:04 PM
http://blog.csdn.net/fyxichen/article/details/50991805
Submitted by admin on 2017, June 11, 1:17 AM
golang时间处理
相关包 "time"
时间戳
当前时间戳
fmt.Println(time.Now().Unix()) # 1389058332
str格式化时间
当前格式化时间
fmt.Println(time.Now().Format("2006-01-02 15:04:05")) # 这是个奇葩,必须是这个时间点, 据说是go诞生之日, 记忆方法:6-1-2-3-4-5 # 2014-01-07 09:42:20
时间戳转str格式化时间
str_time := time.Unix(1389058332, 0).Format("2006-01-02 15:04:05") fmt.Println(str_time) # 2014-01-07 09:32:12
str格式化时间转时间戳
这个比较麻烦
the_time := time.Date(2014, 1, 7, 5, 50, 4, 0, time.Local) unix_time := the_time.Unix() fmt.Println(unix_time) # 389045004
还有一种方法,使用time.Parse
the_time, err := time.Parse("2006-01-02 15:04:05", "2014-01-08 09:04:41") if err == nil { unix_time := the_time.Unix() fmt.Println(unix_time) } # 1389171881
func main () { now := time.Now() yesterday := now.AddDate( 0, -1, 0 ) bef_yes := yesterday.AddDate ( 0, -1, 0 ) fmt.Printf("Today:%s\n", now.Format("200601")) fmt.Printf("Yesterday:%s\n", yesterday.Format("200601")) fmt.Printf("Yesterdat before Yesterday:%s\n",bef_yes.Format("200601"))先把当前时间格式化成相同格式的字符串,然后使用time的Before, After, Equal 方法即可.
Submitted by admin on 2017, June 8, 2:48 PM
http://studygolang.com/articles/9959
Submitted by admin on 2017, June 8, 10:37 AM
Submitted by admin on 2017, June 6, 10:09 PM
http://ethfans.org/posts/tools-and-technologies-in-the-ethereum-ecosystem
Submitted by admin on 2017, June 4, 1:40 AM
简单说就是设计数据库的时候不要出现null,处理起来非常费力。Null的type很有限,例如没有sql.NullUint64; null值没有默认零值。
for rows.Next() { var s sql.NullString err := rows.Scan(&s) // check err if s.Valid { // use s.String } else { // NULL value } }
而对于在Go中构建页面, text/template 中的很多功能不会自动判断Nullable类型,比如 {{if .Property}} ,如果 Property 属性是Nullable类型,且他是 NULL 即 Valid 属性为 false ,但是模板中的 if 还是会认为 true ,因为这个Nullable类型本身是一个值所以 if 会认为是 true,而Nullable类型本身到底是不是 NULL 根本没有意义,所以必须要写 {{if .Property.Valid}}。在输出上,也要写 {{.Property.String}} (不同Nullable类型值得属性会不一样,这里以 sql.NullString 演示)。
或者用实际代码演示这个问题:
package main import ( "bytes" "database/sql" "fmt" "text/template" ) type Test struct { EmptyString sql.NullString NonEmptyString sql.NullString } func main() { test := &Test{} test.EmptyString = sql.NullString{Valid: false} test.NonEmptyString = sql.NullString{Valid: true, String: "Mgen"} template := template.Must(template.New("test").Parse("{{if .EmptyString}}{{.NonEmptyString}}{{end}}")) buffer := &bytes.Buffer{} err := template.Execute(buffer, test) if err != nil { panic(err) } fmt.Print(buffer.String()) }
这段代码会输出:
{Mgen true}
验证了上面讲的两个问题:
NULL 的Nullable类型会在模板 if 中直接理解成 true .{Mgen true} 实际上就是把 sql.NullString 的两个内部属性全部输出出来了。Go中 NullString 类型定义:
type NullString struct { String string Valid bool // Valid is true if String is not NULL }
template := template.Must(template.New("test").Parse("{{if .EmptyString.Valid}}{{.NonEmptyString.String}}{{end}}"))
总之一旦遇到数据库中的 NULL ,还是会稍微有些麻烦的,目前的解决方案可供选择:
NULL 值,或者使用 ISNULL 或 COALESCE 对 NULL 值坐下处理。NULL 值转换成空值, 这是文章开头我说的愿望:joy:,目前不支持 。Submitted by admin on 2017, May 25, 12:19 PM
#./configure --prefix=/usr/local/squid3 //指定软件的安装路径
--disable-internal-dns //使用自己内部DNS查询
--disable-ident-lookups //防止系统使用RFC931规定的身份识别方
--disable-carp //Cache数组路由协议(CARP)用来转发丢失的cache到父cache的数组或cluste
--disable-wccp //用于阻止或分发HTTP请求到一个或多个caches
--enable-gnuregex //支持GNU正则表达式
--enable-async-io=240 //等同于同时开启./configure如下三个选项:
--with-aufs-threads=N_THREADS
--with-pthreads
--enable-storeio=ufs,aufs
Submitted by admin on 2017, May 25, 12:13 PM
禁止终端用户在任何客户机上下载文件扩展名为mp3、exe、zip和rar类型的文件
acl badfile urlpath_regex –i .mp3$ .exe$ .zip$ .rar$ .rmvb$ .rm$ .mp4$ ……
http_access deny badfile
禁止客户机IP地址在192.168.2.0子网的所有终端客户在星期一到星期五的9:00到18:00访问Internet资源
acl clientnet src 192.168.2.0/24
acl worktime time MTWHF 9:00-18:00
http_access deny clientnet worktime
限制IP地址为192.168.1.102的客户机并发连接的最大连接数为5
acl clientip src 192.168.1.102
acl clientmaxconn maxconn 5
http_access deny clientip clientmaxconn
禁止所有终端用户访问域名包含为google.com的网站
acl badurl url_regex –i google.com
http_access deny badurl
禁止所有终端用户访问域名为www.google.com的网站
acl baddomain dstdomain –i www.google.com
http_access deny baddomain