<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title>meisw's blog</title>
		<link>http://meisw.wdlinux.cn//</link>
		<description>工作,学习,生活,这里将会有一些记录.     备用域名:http://meisw.wdlinux.cn</description>
		<copyright>Copyright (C) 2004 Security Angel Team [S4T] All Rights Reserved.</copyright>
		<generator>SaBlog-X Version 1.6 Build 20080806</generator>
		<lastBuildDate>Fri, 05 Jun 2026 02:14:00 +0000</lastBuildDate>
		<ttl>30</ttl>
		<item>
			<guid>http://meisw.wdlinux.cn//show-1074-1.html</guid>
			<title>websocket proxy</title>
			<author>admin</author>
			<description><![CDATA[<p>&nbsp;package main</p>
<div>&nbsp;</div>
<div>import (</div>
<div>&nbsp; &nbsp; &quot;flag&quot;</div>
<div>&nbsp; &nbsp; &quot;log&quot;</div>
<div>&nbsp; &nbsp; &quot;net/url&quot;</div>
<div>&nbsp; &nbsp; &quot;os&quot;</div>
<div>&nbsp; &nbsp; &quot;os/signal&quot;</div>
<div>&nbsp; &nbsp; &quot;time&quot;</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; &quot;github.com/gorilla/websocket&quot;</div>
<div>&nbsp; &nbsp; &quot;net/http&quot;</div>
<div>)</div>
<div>&nbsp;</div>
<div>var addrWebsocket = flag.String(&quot;addrWebsocket&quot;, &quot;echo.websocket.org&quot;, &quot;http service address&quot;)</div>
<div>&nbsp;</div>
<div>func main() {</div>
<div>&nbsp; &nbsp; flag.Parse()</div>
<div>&nbsp; &nbsp; log.SetFlags(0)</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; interrupt := make(chan os.Signal, 1)</div>
<div>&nbsp; &nbsp; signal.Notify(interrupt, os.Interrupt)</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; //Initialize the WebSocket URL and the Path to follow</div>
<div>&nbsp; &nbsp; uWS := url.URL{Scheme: &quot;wss&quot;, Host: *addrWebsocket}</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; //Initialize the Proxy URL and the Path to follow</div>
<div>&nbsp; &nbsp; uProxy, _ := url.Parse(&quot;https://hide.me/en/proxy&quot;)</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; //Set the Dialer (especially the proxy)</div>
<div>&nbsp; &nbsp; dialer := websocket.Dialer{</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; Proxy: http.ProxyURL(uProxy),</div>
<div>&nbsp; &nbsp; }</div>
<div>&nbsp; &nbsp; //dialer := websocket.DefaultDialer ==&gt; with this default dialer, it works !</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; c, _, err := dialer.Dial(uWS.String(), nil) // ==&gt; With the proxy config, it fails here !</div>
<div>&nbsp; &nbsp; defer c.Close()</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; done := make(chan struct{})</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; go func() {</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; defer c.Close()</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; defer close(done)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; for {</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _, message, err := c.ReadMessage()</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if err != nil {</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; log.Println(&quot;read:&quot;, err)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; log.Printf(&quot;recv: %s&quot;, message)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; }</div>
<div>&nbsp; &nbsp; }()</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; ticker := time.NewTicker(time.Second)</div>
<div>&nbsp; &nbsp; defer ticker.Stop()</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; for {</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; select {</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; case t := &lt;-ticker.C:</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; err := c.WriteMessage(websocket.TextMessage, []byte(t.String()))</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if err != nil {</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; log.Println(&quot;write:&quot;, err)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; case &lt;-interrupt:</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; log.Println(&quot;interrupt&quot;)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; err := c.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, &quot;&quot;))</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if err != nil {</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; log.Println(&quot;write close:&quot;, err)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; select {</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case &lt;-done:</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case &lt;-time.After(time.Second):</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c.Close()</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; }</div>
<div>&nbsp; &nbsp; }</div>
<div>}</div>]]></description>
			<link>http://meisw.wdlinux.cn//show-1074-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-47-1.html">golang</category>
			<pubDate>2019-05-14 17:14</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-1073-1.html</guid>
			<title>默认的 rand.Intn () 生成的是伪随机数</title>
			<author>admin</author>
			<description><![CDATA[<p>&nbsp;<span style="color: rgb(99, 107, 111); font-family: &quot;Helvetica Neue&quot;, NotoSansHans-Regular, AvenirNext-Regular, arial, &quot;Hiragino Sans GB&quot;, &quot;Microsoft Yahei&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif; font-size: 15px;">rand.Intn () 函数是个伪随机函数，不管运行多少次都只会返回同样的随机数，因为它默认的资源就是单一值，所以必须调用 rand.Seed (), 并且传入一个变化的值作为参数，如&nbsp;</span><code style="box-sizing: border-box; font-family: monaco, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; background: rgb(249, 250, 250); margin: 5px; color: rgb(133, 128, 128); border-radius: 4px; border: 1px solid rgb(228, 228, 228); max-width: 740px; overflow-x: auto; padding: 1px 2px;">time.Now().UnixNano()</code><span style="color: rgb(99, 107, 111); font-family: &quot;Helvetica Neue&quot;, NotoSansHans-Regular, AvenirNext-Regular, arial, &quot;Hiragino Sans GB&quot;, &quot;Microsoft Yahei&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif; font-size: 15px;">&nbsp;, 就是可以生成时刻变化的值.</span></p>
<div><span style="color: rgb(99, 107, 111); font-family: &quot;Helvetica Neue&quot;, NotoSansHans-Regular, AvenirNext-Regular, arial, &quot;Hiragino Sans GB&quot;, &quot;Microsoft Yahei&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif; font-size: 15px;"><br />
</span></div>
<div>
<div style=""><font color="#636b6f" face="Helvetica Neue, NotoSansHans-Regular, AvenirNext-Regular, arial, Hiragino Sans GB, Microsoft Yahei, WenQuanYi Micro Hei, sans-serif"><span style="font-size: 15px;">package main</span></font></div>
<div style=""><font color="#636b6f" face="Helvetica Neue, NotoSansHans-Regular, AvenirNext-Regular, arial, Hiragino Sans GB, Microsoft Yahei, WenQuanYi Micro Hei, sans-serif"><span style="font-size: 15px;"><br />
</span></font></div>
<div style=""><font color="#636b6f" face="Helvetica Neue, NotoSansHans-Regular, AvenirNext-Regular, arial, Hiragino Sans GB, Microsoft Yahei, WenQuanYi Micro Hei, sans-serif"><span style="font-size: 15px;">import (&quot;fmt&quot;</span></font></div>
<div style=""><font color="#636b6f" face="Helvetica Neue, NotoSansHans-Regular, AvenirNext-Regular, arial, Hiragino Sans GB, Microsoft Yahei, WenQuanYi Micro Hei, sans-serif"><span style="font-size: 15px;">&nbsp; &nbsp; &nbsp; &nbsp; &quot;math/rand&quot;</span></font></div>
<div style=""><font color="#636b6f" face="Helvetica Neue, NotoSansHans-Regular, AvenirNext-Regular, arial, Hiragino Sans GB, Microsoft Yahei, WenQuanYi Micro Hei, sans-serif"><span style="font-size: 15px;">&nbsp; &nbsp; &nbsp; &nbsp; &quot;time&quot;)</span></font></div>
<div style=""><font color="#636b6f" face="Helvetica Neue, NotoSansHans-Regular, AvenirNext-Regular, arial, Hiragino Sans GB, Microsoft Yahei, WenQuanYi Micro Hei, sans-serif"><span style="font-size: 15px;"><br />
</span></font></div>
<div style=""><font color="#636b6f" face="Helvetica Neue, NotoSansHans-Regular, AvenirNext-Regular, arial, Hiragino Sans GB, Microsoft Yahei, WenQuanYi Micro Hei, sans-serif"><span style="font-size: 15px;">func main() {</span></font></div>
<div style=""><font color="#636b6f" face="Helvetica Neue, NotoSansHans-Regular, AvenirNext-Regular, arial, Hiragino Sans GB, Microsoft Yahei, WenQuanYi Micro Hei, sans-serif"><span style="font-size: 15px;">&nbsp; &nbsp; // 初始化随机数的资源库, 如果不执行这行, 不管运行多少次都返回同样的值</span></font></div>
<div style=""><font color="#636b6f" face="Helvetica Neue, NotoSansHans-Regular, AvenirNext-Regular, arial, Hiragino Sans GB, Microsoft Yahei, WenQuanYi Micro Hei, sans-serif"><span style="font-size: 15px;">&nbsp; &nbsp; rand.Seed(time.Now().UnixNano())</span></font></div>
<div style=""><font color="#636b6f" face="Helvetica Neue, NotoSansHans-Regular, AvenirNext-Regular, arial, Hiragino Sans GB, Microsoft Yahei, WenQuanYi Micro Hei, sans-serif"><span style="font-size: 15px;">&nbsp; &nbsp; fmt.Println(&quot;A number from 1-100&quot;, rand.Intn(81))</span></font></div>
<div style=""><font color="#636b6f" face="Helvetica Neue, NotoSansHans-Regular, AvenirNext-Regular, arial, Hiragino Sans GB, Microsoft Yahei, WenQuanYi Micro Hei, sans-serif"><span style="font-size: 15px;">}</span></font></div>
</div>
<div style=""><font color="#636b6f" face="Helvetica Neue, NotoSansHans-Regular, AvenirNext-Regular, arial, Hiragino Sans GB, Microsoft Yahei, WenQuanYi Micro Hei, sans-serif"><span style="font-size: 15px;"><br />
</span></font></div>
<div style=""><font color="#636b6f" face="Helvetica Neue, NotoSansHans-Regular, AvenirNext-Regular, arial, Hiragino Sans GB, Microsoft Yahei, WenQuanYi Micro Hei, sans-serif"><span style="font-size: 15px;">--------------</span></font></div>
<div style=""><font color="#636b6f" face="Helvetica Neue, NotoSansHans-Regular, AvenirNext-Regular, arial, Hiragino Sans GB, Microsoft Yahei, WenQuanYi Micro Hei, sans-serif"><span style="font-size: 15px;">
<div>//rand.Float64 返回一个64位浮点数 f，0.0 &lt;= f &lt;= 1.0。</div>
<div>&nbsp; &nbsp; fmt.Println(rand.Float64())</div>
<div>//这个技巧可以用来生成其他范围的随机浮点数，例如5.0 &lt;= f &lt;= 10.0</div>
<div>&nbsp; &nbsp; fmt.Print((rand.Float64()*5)+5, &quot;,&quot;)</div>
<div>&nbsp; &nbsp; fmt.Print((rand.Float64() * 5) + 5)</div>
<div>&nbsp; &nbsp; fmt.Println()</div>
<div>//要让伪随机数生成器有确定性，可以给它一个明确的种子。</div>
<div>&nbsp; &nbsp; s1 := rand.NewSource(42)</div>
<div>&nbsp; &nbsp; r1 := rand.New(s1)</div>
<div>//调用上面返回的 rand.Source 的函数和调用 rand 包中函数是相同的。</div>
<div>&nbsp; &nbsp; fmt.Print(r1.Intn(100), &quot;,&quot;)</div>
<div>&nbsp; &nbsp; fmt.Print(r1.Intn(100))</div>
<div>&nbsp; &nbsp; fmt.Println()</div>
<div>如果使用相同的种子生成的随机数生成器，将会产生相同的随机数序列。</div>
<div>&nbsp; &nbsp; s2 := rand.NewSource(42)</div>
<div>&nbsp; &nbsp; r2 := rand.New(s2)</div>
<div>&nbsp; &nbsp; fmt.Print(r2.Intn(100), &quot;,&quot;)</div>
<div>&nbsp; &nbsp; fmt.Print(r2.Intn(100))</div>
<div>&nbsp; &nbsp; fmt.Println()</div>
</span></font></div>]]></description>
			<link>http://meisw.wdlinux.cn//show-1073-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-47-1.html">golang</category>
			<pubDate>2019-04-29 14:51</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-1072-1.html</guid>
			<title>golang实现md5、RSA、base64 加密解密</title>
			<author>admin</author>
			<description><![CDATA[<p>&nbsp;package tools</p>
<div>&nbsp;</div>
<div>import (</div>
<div><span style="white-space:pre">	</span>&quot;crypto/md5&quot;</div>
<div><span style="white-space:pre">	</span>&quot;crypto/rand&quot;</div>
<div><span style="white-space:pre">	</span>&quot;crypto/rsa&quot;</div>
<div><span style="white-space:pre">	</span>&quot;crypto/x509&quot;</div>
<div><span style="white-space:pre">	</span>&quot;encoding/base64&quot;</div>
<div><span style="white-space:pre">	</span>&quot;encoding/hex&quot;</div>
<div><span style="white-space:pre">	</span>&quot;encoding/pem&quot;</div>
<div><span style="white-space:pre">	</span>&quot;errors&quot;</div>
<div>)</div>
<div>&nbsp;</div>
<div>const (</div>
<div><span style="white-space:pre">	</span>base64Table = &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/&quot;</div>
<div>)</div>
<div>&nbsp;</div>
<div>var coder = base64.NewEncoding(base64Table)</div>
<div>&nbsp;</div>
<div>func Base64Encode(src []byte) []byte {</div>
<div><span style="white-space:pre">	</span>return []byte(coder.EncodeToString(src))</div>
<div>}</div>
<div>&nbsp;</div>
<div>func Base64Decode(src []byte) ([]byte, error) {</div>
<div><span style="white-space:pre">	</span>return coder.DecodeString(string(src))</div>
<div>}</div>
<div>&nbsp;</div>
<div>func RsaEncrypt(origData []byte, publicKey string) ([]byte, error) {</div>
<div><span style="white-space:pre">	</span>block, _ := pem.Decode([]byte(publicKey))</div>
<div><span style="white-space:pre">	</span>if block == nil {</div>
<div><span style="white-space:pre">		</span>return nil, errors.New(&quot;public key error&quot;)</div>
<div><span style="white-space:pre">	</span>}</div>
<div><span style="white-space:pre">	</span>pubInterface, err := x509.ParsePKIXPublicKey(block.Bytes)</div>
<div><span style="white-space:pre">	</span>if err != nil {</div>
<div><span style="white-space:pre">		</span>return nil, err</div>
<div><span style="white-space:pre">	</span>}</div>
<div><span style="white-space:pre">	</span>pub := pubInterface.(*rsa.PublicKey)</div>
<div><span style="white-space:pre">	</span>return rsa.EncryptPKCS1v15(rand.Reader, pub, origData)</div>
<div>}</div>
<div>&nbsp;</div>
<div>func RsaDecrypt(ciphertext []byte, privateKey string) ([]byte, error) {</div>
<div><span style="white-space:pre">	</span>block, _ := pem.Decode([]byte(privateKey))</div>
<div><span style="white-space:pre">	</span>if block == nil {</div>
<div><span style="white-space:pre">		</span>return nil, errors.New(&quot;private key error!&quot;)</div>
<div><span style="white-space:pre">	</span>}</div>
<div><span style="white-space:pre">	</span>priv, err := x509.ParsePKCS1PrivateKey(block.Bytes)</div>
<div><span style="white-space:pre">	</span>if err != nil {</div>
<div><span style="white-space:pre">		</span>return nil, err</div>
<div><span style="white-space:pre">	</span>}</div>
<div><span style="white-space:pre">	</span>return rsa.DecryptPKCS1v15(rand.Reader, priv, ciphertext)</div>
<div>}</div>
<div>&nbsp;</div>
<div>func Md5Encrypt(data string) string {</div>
<div><span style="white-space:pre">	</span>md5Ctx := md5.New()&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //md5 init</div>
<div><span style="white-space:pre">	</span>md5Ctx.Write([]byte(data))&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//md5 updata</div>
<div><span style="white-space:pre">	</span>cipherStr := md5Ctx.Sum(nil)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//md5 final</div>
<div><span style="white-space:pre">	</span>encryptedData := hex.EncodeToString(cipherStr) //hex_digest</div>
<div><span style="white-space:pre">	</span>return encryptedData</div>
<div>}</div>
<div>&nbsp;</div>
<div>--------</div>
<div>https://blog.csdn.net/yue7603835/article/details/73433617</div>]]></description>
			<link>http://meisw.wdlinux.cn//show-1072-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-47-1.html">golang</category>
			<pubDate>2019-04-18 11:04</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-1044-1.html</guid>
			<title>Golang同步:条件变量和锁组合使用</title>
			<author>admin</author>
			<description><![CDATA[<p>&nbsp;https://studygolang.com/articles/5776</p>]]></description>
			<link>http://meisw.wdlinux.cn//show-1044-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-47-1.html">golang</category>
			<pubDate>2018-07-24 11:27</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-1043-1.html</guid>
			<title>golang 1.8 并发安全Map简单实现</title>
			<author>admin</author>
			<description><![CDATA[<p>
<div class="codeText">
<div class="codeHead">XML/HTML代码</div>
<ol start="1" class="dp-xml">
    <li class="alt"><span><span>type&nbsp;SafeMap&nbsp;struct&nbsp;{&nbsp;&nbsp;</span></span></li>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;sync.RWMutex&nbsp;&nbsp;</span></li>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;Map&nbsp;map[int64]string&nbsp;&nbsp;</span></li>
    <li class=""><span>}&nbsp;&nbsp;</span></li>
    <li class="alt"><span>&nbsp;&nbsp;</span></li>
    <li class=""><span>func&nbsp;NewSafeMap(size&nbsp;int)&nbsp;*SafeMap&nbsp;{&nbsp;&nbsp;</span></li>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;sm&nbsp;<span class="attribute">:</span><span>=&nbsp;</span><span class="attribute-value">new</span><span>(SafeMap)&nbsp;&nbsp;</span></span></li>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">sm.Map</span><span>&nbsp;=&nbsp;</span><span class="attribute-value">make</span><span>(map[int64]string,&nbsp;size)&nbsp;&nbsp;</span></span></li>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;sm&nbsp;&nbsp;</span></li>
    <li class=""><span>}&nbsp;&nbsp;</span></li>
    <li class="alt"><span>&nbsp;&nbsp;</span></li>
    <li class=""><span>func&nbsp;(sm&nbsp;*SafeMap)&nbsp;ReadMap(key&nbsp;int64)&nbsp;string&nbsp;{&nbsp;&nbsp;</span></li>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;sm.RLock()&nbsp;&nbsp;</span></li>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;value&nbsp;<span class="attribute">:</span><span>=&nbsp;</span><span class="attribute-value">sm</span><span>.Map[key]&nbsp;&nbsp;</span></span></li>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;sm.RUnlock()&nbsp;&nbsp;</span></li>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;value&nbsp;&nbsp;</span></li>
    <li class="alt"><span>}&nbsp;&nbsp;</span></li>
    <li class=""><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span>func&nbsp;(sm&nbsp;*SafeMap)&nbsp;WriteMap(key&nbsp;int64,&nbsp;value&nbsp;string)&nbsp;{&nbsp;&nbsp;</span></li>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;sm.Lock()&nbsp;&nbsp;</span></li>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;sm.Map[key]&nbsp;=&nbsp;value&nbsp;&nbsp;</span></li>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;sm.Unlock()&nbsp;&nbsp;</span></li>
    <li class="alt"><span>}&nbsp;&nbsp;</span></li>
    <li class=""><span>&nbsp;&nbsp;</span></li>
    <li class="alt"><span>//&nbsp;用于for&nbsp;k，_&nbsp;<span class="attribute">:</span><span>=&nbsp;</span><span class="attribute-value">range</span><span>&nbsp;m.Keys(){v&nbsp;</span><span class="attribute">:</span><span>=&nbsp;</span><span class="attribute-value">m</span><span>.ReadMap(k)&nbsp;....}&nbsp;&nbsp;</span></span></li>
    <li class=""><span>func&nbsp;(sm&nbsp;*SafeMap)&nbsp;Keys()&nbsp;[]int64&nbsp;{&nbsp;&nbsp;</span></li>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;sm.RLock()&nbsp;&nbsp;</span></li>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;value&nbsp;<span class="attribute">:</span><span>=&nbsp;</span><span class="attribute-value">make</span><span>([]int64,&nbsp;0)&nbsp;&nbsp;</span></span></li>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;k,&nbsp;_&nbsp;<span class="attribute">:</span><span>=&nbsp;</span><span class="attribute-value">range</span><span>&nbsp;sm.Map&nbsp;{&nbsp;&nbsp;</span></span></li>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="attribute">value</span><span>&nbsp;=&nbsp;</span><span class="attribute-value">append</span><span>(value,&nbsp;k)&nbsp;&nbsp;</span></span></li>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li>
    <li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;sm.RUnlock()&nbsp;&nbsp;</span></li>
    <li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;value&nbsp;&nbsp;</span></li>
    <li class=""><span>}&nbsp;&nbsp;</span></li>
</ol>
</div>
</p>
<p>https://blog.csdn.net/qq_17612199/article/details/79601222</p>]]></description>
			<link>http://meisw.wdlinux.cn//show-1043-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-47-1.html">golang</category>
			<pubDate>2018-07-23 15:08</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-1042-1.html</guid>
			<title>golang:An operation on a socket could not be performed because the system lacked sufficient buffer s</title>
			<author>admin</author>
			<description><![CDATA[<p>&nbsp;<span style="color: rgb(79, 79, 79); font-family: -apple-system, &quot;SF UI Text&quot;, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif, SimHei, SimSun; font-size: 16px; text-align: justify;">1、问题</span><span style="color: rgb(79, 79, 79); font-family: -apple-system, &quot;SF UI Text&quot;, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif, SimHei, SimSun; font-size: 16px; text-align: justify;">&nbsp;</span></p>
<p style="box-sizing: border-box; outline: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, &quot;SF UI Text&quot;, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif, SimHei, SimSun;">conn, err := net.Dial(&ldquo;tcp&rdquo;, &lsquo;127.0.0.1:50001&rsquo;)</p>
<p style="box-sizing: border-box; outline: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, &quot;SF UI Text&quot;, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif, SimHei, SimSun;">执行此语句报错详细报错信息&nbsp;<br style="box-sizing: border-box; outline: 0px; word-break: break-all;" />
dial tcp 127.0.0.1:50001: An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full.</p>
<p style="box-sizing: border-box; outline: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, &quot;SF UI Text&quot;, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif, SimHei, SimSun;">此报错的原因一般是系统端口已用尽，无法再建立新的Socket连接</p>
<p style="box-sizing: border-box; outline: 0px; margin-bottom: 16px; line-height: 26px; text-align: justify; word-break: break-all;"><font color="#4f4f4f" face="-apple-system, SF UI Text, Arial, PingFang SC, Hiragino Sans GB, Microsoft YaHei, WenQuanYi Micro Hei, sans-serif, SimHei, SimSun"><span style="font-size: 16px;"><a href="https://blog.csdn.net/xia_xing/article/details/53352658">https://blog.csdn.net/xia_xing/article/details/53352658</a></span></font></p>
<h1 class="title-article" style="box-sizing: inherit; outline: 0px; padding: 0px; margin: 0px; font-size: 24px; word-break: break-all; color: rgb(51, 51, 51); font-family: &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, sans-serif;">服务器 TIME_WAIT和CLOSE_WAIT</h1>
<p style="box-sizing: border-box; outline: 0px; margin-bottom: 16px; line-height: 26px; text-align: justify; word-break: break-all;"><font color="#4f4f4f" face="-apple-system, SF UI Text, Arial, PingFang SC, Hiragino Sans GB, Microsoft YaHei, WenQuanYi Micro Hei, sans-serif, SimHei, SimSun"><span style="font-size: 16px;"><a href="https://blog.csdn.net/xia_xing/article/details/53352486">https://blog.csdn.net/xia_xing/article/details/53352486</a></span></font></p>
<h1 class="title-article" style="box-sizing: inherit; outline: 0px; padding: 0px; margin: 0px; font-size: 24px; word-break: break-all; color: rgb(51, 51, 51); font-family: &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, sans-serif;">常见SOCKET错误参数</h1>
<p style="box-sizing: border-box; outline: 0px; margin-bottom: 16px; line-height: 26px; text-align: justify; word-break: break-all;"><font color="#4f4f4f" face="-apple-system, SF UI Text, Arial, PingFang SC, Hiragino Sans GB, Microsoft YaHei, WenQuanYi Micro Hei, sans-serif, SimHei, SimSun"><a href="https://blog.csdn.net/macky0668/article/details/4257721">https://blog.csdn.net/macky0668/article/details/4257721</a></font></p>
<p style="box-sizing: border-box; outline: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, &quot;SF UI Text&quot;, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif, SimHei, SimSun;">&nbsp;</p>
<p style="box-sizing: border-box; outline: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, &quot;SF UI Text&quot;, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif, SimHei, SimSun;">&nbsp;</p>]]></description>
			<link>http://meisw.wdlinux.cn//show-1042-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-47-1.html">golang</category>
			<pubDate>2018-07-06 16:35</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-1038-1.html</guid>
			<title>golang web xss攻击预防</title>
			<author>admin</author>
			<description><![CDATA[<p>&nbsp;<span style="color: rgb(79, 79, 79); font-family: -apple-system, &quot;SF UI Text&quot;, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif, SimHei, SimSun; font-size: 16px; text-align: justify;">从上面访问的结果发现。我们这边的&lt; 之类的符号已经被转义成html 特殊符</span></p>
<p style="box-sizing: border-box; outline: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, &quot;SF UI Text&quot;, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif, SimHei, SimSun;">上面的方法也是可以进行简化的</p>
<p style="box-sizing: border-box; outline: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, &quot;SF UI Text&quot;, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif, SimHei, SimSun;">&nbsp;</p>
<pre style="box-sizing: border-box; outline: 0px; padding: 8px; margin-top: 0px; margin-bottom: 24px; position: relative; word-wrap: break-word; overflow-x: auto; line-height: 22px; word-break: break-all;"><code class="language-plain" style="font-family: Consolas, Inconsolata, Courier, monospace; white-space: pre; box-sizing: border-box; outline: 0px; border-radius: 4px; display: block; line-height: 22px; overflow-x: auto; word-wrap: normal; padding: 8px; word-break: break-all;">package main  import ( 	&quot;fmt&quot; 	&quot;html/template&quot; 	&quot;log&quot; 	&quot;net/http&quot; )  func main() { 	//绑定路由 讲访问 / 绑定给  Handler 方法进行处理 	http.HandleFunc(&quot;/&quot;, Handler) 	http.ListenAndServe(&quot;:8080&quot;, nil) }  func Handler(w http.ResponseWriter, req *http.Request) { 	err := req.ParseForm() 	//如果解析失败 直接退出 输出对应的错误原因 	if err != nil { 		log.Fatal(nil) 	} 	//获取 传递的name 参数 	user_pro := req.FormValue(&quot;name&quot;) 	fmt.Fprintf(w, &quot;%s&quot;, xss_hander(user_pro))  } func xss_hander(s string) string { 	return template.HTMLEscapeString(s) }</code><code class="language-plain" style="box-sizing: border-box; outline: 0px; border-radius: 4px; display: block; line-height: 22px; overflow-x: auto; word-wrap: normal; padding: 8px; word-break: break-all;"><font face="Consolas, Inconsolata, Courier, monospace"><a href="https://blog.csdn.net/liangguangchuan/article/details/54617685">https://blog.csdn.net/liangguangchuan/article/details/54617685</a></font></code><code class="language-plain" style="font-family: Consolas, Inconsolata, Courier, monospace; white-space: pre; box-sizing: border-box; outline: 0px; border-radius: 4px; display: block; line-height: 22px; overflow-x: auto; word-wrap: normal; padding: 8px; word-break: break-all;"><br /></code></pre>]]></description>
			<link>http://meisw.wdlinux.cn//show-1038-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-47-1.html">golang</category>
			<pubDate>2018-06-30 12:42</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-1037-1.html</guid>
			<title>beego orm 调用多次sql的事物同步</title>
			<author>admin</author>
			<description><![CDATA[<p>&nbsp;https://blog.csdn.net/easternunbeaten/article/details/72456240</p>
<div>&nbsp;</div>
<div>https://beego.me/docs/mvc/model/transaction.md</div>]]></description>
			<link>http://meisw.wdlinux.cn//show-1037-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-47-1.html">golang</category>
			<pubDate>2018-06-30 10:25</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-1035-1.html</guid>
			<title>golang中map并发读写问题及解决方法</title>
			<author>admin</author>
			<description><![CDATA[<p>&nbsp;https://blog.csdn.net/qq_17612199/article/details/79601222</p>
<div>&nbsp;</div>
<div>https://blog.csdn.net/skh2015java/article/details/60334091</div>]]></description>
			<link>http://meisw.wdlinux.cn//show-1035-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-47-1.html">golang</category>
			<pubDate>2018-06-30 10:23</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-1034-1.html</guid>
			<title>map按key和按value排序</title>
			<author>admin</author>
			<description><![CDATA[<p>&nbsp;https://studygolang.com/articles/10530</p>
<p>&nbsp;</p>
<p>--------------</p>
<p style="color: rgb(68, 68, 68); font-family: &quot;Droid Serif&quot;, Georgia, &quot;Times New Roman&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;WenQuanYi Micro Hei&quot;, &quot;Microsoft Yahei&quot;, serif;">可以把k，v组织为一个struct的成员，把其用slice存放后，按照自己的排序方式对slice进行排序。</p>
<p style="color: rgb(68, 68, 68); font-family: &quot;Droid Serif&quot;, Georgia, &quot;Times New Roman&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;WenQuanYi Micro Hei&quot;, &quot;Microsoft Yahei&quot;, serif;">这种思想可以实现你想要的任意排序。</p>]]></description>
			<link>http://meisw.wdlinux.cn//show-1034-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-47-1.html">golang</category>
			<pubDate>2018-06-30 00:43</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-1033-1.html</guid>
			<title>golang基础-排序、二分查找、map、map排序反转</title>
			<author>admin</author>
			<description><![CDATA[<p>&nbsp;https://blog.csdn.net/u013210620/article/details/78344771</p>]]></description>
			<link>http://meisw.wdlinux.cn//show-1033-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-47-1.html">golang</category>
			<pubDate>2018-06-29 23:38</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-1032-1.html</guid>
			<title>正则表达式(括号)、[中括号]、{大括号}的区别小结 通用所有语言 系统</title>
			<author>admin</author>
			<description><![CDATA[<p>&nbsp;<span style="color: rgb(102, 102, 102); font-family: tahoma, arial, 宋体;">正则表达式的() [] {}有不同的意思。</span></p>
<p style="margin: 10px auto; padding-top: 5px; padding-bottom: 5px; font-family: tahoma, arial, 宋体; border: 0px; outline: 0px; vertical-align: baseline; color: rgb(102, 102, 102); line-height: 25.2px;">() 是为了提取匹配的字符串。表达式中有几个()就有几个相应的匹配字符串。</p>
<p style="margin: 10px auto; padding-top: 5px; padding-bottom: 5px; font-family: tahoma, arial, 宋体; border: 0px; outline: 0px; vertical-align: baseline; color: rgb(102, 102, 102); line-height: 25.2px;">(\s*)表示连续空格的字符串。</p>
<p style="margin: 10px auto; padding-top: 5px; padding-bottom: 5px; font-family: tahoma, arial, 宋体; border: 0px; outline: 0px; vertical-align: baseline; color: rgb(102, 102, 102); line-height: 25.2px;">[]是定义匹配的字符范围。比如 [a-zA-Z0-9] 表示相应位置的字符要匹配英文字符和数字。[\s*]表示空格或者*号。</p>
<p style="margin: 10px auto; padding-top: 5px; padding-bottom: 5px; font-family: tahoma, arial, 宋体; border: 0px; outline: 0px; vertical-align: baseline; color: rgb(102, 102, 102); line-height: 25.2px;">{}一般用来表示匹配的长度，比如 \s{3} 表示匹配三个空格，\s[1,3]表示匹配一到三个空格。</p>
<p style="margin: 10px auto; padding-top: 5px; padding-bottom: 5px; font-family: tahoma, arial, 宋体; border: 0px; outline: 0px; vertical-align: baseline; color: rgb(102, 102, 102); line-height: 25.2px;">(0-9) 匹配 '0-9&prime; 本身。 [0-9]* 匹配数字（注意后面有 *，可以为空）[0-9]+ 匹配数字（注意后面有 +，不可以为空）{1-9} 写法错误。</p>
<p style="margin: 10px auto; padding-top: 5px; padding-bottom: 5px; font-family: tahoma, arial, 宋体; border: 0px; outline: 0px; vertical-align: baseline; color: rgb(102, 102, 102); line-height: 25.2px;">[0-9]{0,9} 表示长度为 0 到 9 的数字字符串。</p>
<p style="margin: 10px auto; padding-top: 5px; padding-bottom: 5px; font-family: tahoma, arial, 宋体; border: 0px; outline: 0px; vertical-align: baseline; color: rgb(102, 102, 102); line-height: 25.2px;">&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;</p>
<p style="margin: 10px auto; padding-top: 5px; padding-bottom: 5px; font-family: tahoma, arial, 宋体; border: 0px; outline: 0px; vertical-align: baseline; color: rgb(102, 102, 102); line-height: 25.2px;">&nbsp;</p>
<p style="margin: 10px auto; font-family: &quot;Lucida Grande&quot;, Verdana, &quot;Bitstream Vera Sans&quot;, Arial, sans-serif; border: none; outline: 0px; font-size: 13px; vertical-align: baseline; color: rgb(51, 51, 51); line-height: 24.7px; list-style: none;"><strong style="margin: 0px; padding: 0px; border: 0px; outline: 0px; font-size: 16px; vertical-align: baseline;">圆括号()是组</strong>，主要应用在限制多选结构的范围/分组/捕获文本/环视/特殊模式处理<br />
示例：<br />
1、(abc|bcd|cde)，表示这一段是abc、bcd、cde三者之一均可，顺序也必须一致<br />
2、(abc)?，表示这一组要么一起出现，要么不出现，出现则按此组内的顺序出现<br />
3、(?:abc)表示找到这样abc这样一组，但不记录，不保存到$变量中，否则可以通过$x取第几个括号所匹配到的项，比如：(aaa)(bbb)(ccc)(?:ddd)(eee)，可以用$1获取(aaa)匹配到的内容，而$3则获取到了(ccc)匹配到的内容，而$4则获取的是由(eee)匹配到的内容，因为前一对括号没有保存变量<br />
4、a(?=bbb) 顺序环视 表示a后面必须紧跟3个连续的b<br />
5、(?i:xxxx) 不区分大小写 (?s:.*) 跨行匹配.可以匹配回车符</p>
<p style="margin: 10px auto; font-family: &quot;Lucida Grande&quot;, Verdana, &quot;Bitstream Vera Sans&quot;, Arial, sans-serif; border: none; outline: 0px; font-size: 13px; vertical-align: baseline; color: rgb(51, 51, 51); line-height: 24.7px; list-style: none;"><strong style="margin: 0px; padding: 0px; border: 0px; outline: 0px; font-size: 16px; vertical-align: baseline;">方括号是单个匹配</strong>，字符集/排除字符集/命名字符集<br />
示例：<br />
1、[0-3]，表示找到这一个位置上的字符只能是0到3这四个数字，与(abc|bcd|cde)的作用比较类似，但圆括号可以匹配多个连续的字符，而一对方括号只能匹配单个字符<br />
2、[^0-3]，表示找到这一个位置上的字符只能是除了0到3之外的所有字符<br />
3、[:digit:] 0-9 [:alnum:] A-Za-z0-9</p>
<p style="margin: 10px auto; font-family: &quot;Lucida Grande&quot;, Verdana, &quot;Bitstream Vera Sans&quot;, Arial, sans-serif; border: none; outline: 0px; font-size: 13px; vertical-align: baseline; color: rgb(51, 51, 51); line-height: 24.7px; list-style: none;">&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;</p>
<p style="margin: 10px auto; font-family: &quot;Lucida Grande&quot;, Verdana, &quot;Bitstream Vera Sans&quot;, Arial, sans-serif; border: none; outline: 0px; font-size: 13px; vertical-align: baseline; color: rgb(51, 51, 51); line-height: 24.7px; list-style: none;"><span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; line-height: 24.7px;">()和[]有本质的区别</span><br style="line-height: 24.7px;" />
<span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; line-height: 24.7px;">()内的内容表示的是一个子表达式，()本身不匹配任何东西，也不限制匹配任何东西，只是把括号内的内容作为同一个表达式来处理，例如(ab){1,3}，就表示ab一起连续出现最少1次，最多3次。如果没有括号的话，ab{1,3},就表示a，后面紧跟的b出现最少1次，最多3次。另外，括号在匹配模式中也很重要。这个就不延伸了，LZ有兴趣可以自己查查</span><br style="line-height: 24.7px;" />
<span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; line-height: 24.7px;">[]表示匹配的字符在[]中，并且只能出现一次，并且特殊字符写在[]会被当成普通字符来匹配。例如[(a)]，会匹配(、a、)、这三个字符。</span><br style="line-height: 24.7px;" />
<span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; line-height: 24.7px;">所以() [] 无论是作用还是表示的含义，都有天壤之别，没什么联系</span></p>
<p style="margin: 10px auto; border: none; outline: 0px; vertical-align: baseline; line-height: 24.7px; list-style: none;"><span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; line-height: 24.7px; font-size: 13px;"><font color="#333333" face="Lucida Grande, Verdana, Bitstream Vera Sans, Arial, sans-serif">https://www.cnblogs.com/signheart/p/20a396bdbdeb9aa446663395eea4e3c4.html</font></span></p>]]></description>
			<link>http://meisw.wdlinux.cn//show-1032-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-47-1.html">golang</category>
			<pubDate>2018-06-26 23:58</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-1031-1.html</guid>
			<title>Golang开发新手常犯的50个错误</title>
			<author>admin</author>
			<description><![CDATA[<h1 class="title-article" style="box-sizing: inherit; outline: 0px; padding: 0px; margin: 0px; font-size: 24px; word-break: break-all; color: rgb(51, 51, 51); font-family: &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, sans-serif;">Golang开发新手常犯的50个错误</h1>
<p>&nbsp;</p>
<div>https://blog.csdn.net/gezhonglei2007/article/details/52237582</div>
<div>&nbsp;</div>
<div>
<h1 class="title" style="box-sizing: border-box; font-size: 34px; margin: 20px 0px 0px; font-family: -apple-system, &quot;SF UI Display&quot;, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif; line-height: 1.3; color: rgb(51, 51, 51); word-break: break-word !important;">理解Go语言的nil</h1>
</div>
<div>&nbsp;</div>
<div>https://www.jianshu.com/p/dd80f6be7969</div>]]></description>
			<link>http://meisw.wdlinux.cn//show-1031-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-47-1.html">golang</category>
			<pubDate>2018-06-17 18:11</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-1030-1.html</guid>
			<title>Golang的反射reflect深入理解和示例</title>
			<author>admin</author>
			<description><![CDATA[<p>&nbsp;https://juejin.im/post/5a75a4fb5188257a82110544</p>]]></description>
			<link>http://meisw.wdlinux.cn//show-1030-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-47-1.html">golang</category>
			<pubDate>2018-06-14 18:25</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-1029-1.html</guid>
			<title>gorm中的公共方法判断reflect.Value的值是否为空值</title>
			<author>admin</author>
			<description><![CDATA[<p>&nbsp;<span style="background-color: transparent; color: inherit; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; font-size: inherit; white-space: pre-wrap;">func isBlank(value reflect.Value) bool {</span></p>
<pre style="box-sizing: border-box; overflow: auto; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; padding: 10px; margin-top: 0px; margin-bottom: 10.5px; line-height: 1.42857; word-break: break-all; word-wrap: break-word; color: rgb(51, 51, 51); background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); border-radius: 0px;"><code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; font-size: inherit; padding: 0px; color: inherit; background-color: transparent; border-radius: 0px; white-space: pre-wrap;">    switch value.Kind() {     case reflect.String:         return value.Len() == 0     case reflect.Bool:         return !value.Bool()     case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:         return value.Int() == 0     case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:         return value.Uint() == 0     case reflect.Float32, reflect.Float64:         return value.Float() == 0     case reflect.Interface, reflect.Ptr:         return value.IsNil()     }     return reflect.DeepEqual(value.Interface(), reflect.Zero(value.Type()).Interface()) }</code></pre>]]></description>
			<link>http://meisw.wdlinux.cn//show-1029-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-47-1.html">golang</category>
			<pubDate>2018-06-14 18:24</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-1028-1.html</guid>
			<title>golang获取昨天的日期</title>
			<author>admin</author>
			<description><![CDATA[<p>&nbsp;<span style="color: rgb(79, 79, 79); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, SimHei, Arial, SimSun; font-size: 16px; text-align: justify;">golang的time包里面有个AddDate方法,可以通过参数获取之后的日期,如果把参数写成负数就可以获取之前的日期</span></p>
<div><span style="color: rgb(79, 79, 79); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, SimHei, Arial, SimSun; font-size: 16px; text-align: justify;"><br />
</span></div>
<div><span style="text-align: justify;"><font style="">
<div style="color: rgb(79, 79, 79); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, SimHei, Arial, SimSun; font-size: 16px;">nTime := time.Now()&nbsp;&nbsp;</div>
<div style="color: rgb(79, 79, 79); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, SimHei, Arial, SimSun; font-size: 16px;">yesTime := nTime.AddDate(0,0,-1)&nbsp;&nbsp;</div>
<div style="color: rgb(79, 79, 79); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, SimHei, Arial, SimSun; font-size: 16px;">logDay = yesTime.Format(&quot;20060102&quot;)&nbsp;&nbsp;</div>
<div style="color: rgb(79, 79, 79); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, SimHei, Arial, SimSun; font-size: 16px;">&nbsp;</div>
<div style="color: rgb(79, 79, 79); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, SimHei, Arial, SimSun; font-size: 16px;">&nbsp;</div>
<div style="color: rgb(79, 79, 79); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, SimHei, Arial, SimSun; font-size: 16px;">------------------</div>
<div style="color: rgb(79, 79, 79); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, SimHei, Arial, SimSun; font-size: 16px;">
<div align="left" style="font-size: 14px; line-height: 1.7em; background-color: rgb(254, 254, 254); word-wrap: break-word; color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif;"><span style="word-wrap: break-word; color: rgb(69, 69, 69);"><span style="word-wrap: break-word; font-size: 16px;">包名 time</span></span></div>
<div align="left" style="font-size: 14px; line-height: 1.7em; background-color: rgb(254, 254, 254); word-wrap: break-word; color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif;"><span style="word-wrap: break-word; color: rgb(69, 69, 69);"><span style="word-wrap: break-word; font-size: 16px;">当前时间 time.Now()</span></span></div>
<div align="left" style="font-size: 14px; line-height: 1.7em; background-color: rgb(254, 254, 254); word-wrap: break-word; color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif;"><span style="word-wrap: break-word; color: rgb(69, 69, 69);"><span style="word-wrap: break-word; font-size: 16px;">当前时间戳time.Now().Unix()</span></span></div>
<div align="left" style="font-size: 14px; line-height: 1.7em; background-color: rgb(254, 254, 254); word-wrap: break-word; color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif;"><span style="word-wrap: break-word; color: rgb(69, 69, 69);"><span style="word-wrap: break-word; font-size: 16px;">时间格式化string</span></span></div>
<div align="left" style="font-size: 14px; line-height: 1.7em; background-color: rgb(254, 254, 254); word-wrap: break-word; color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif;"><span style="word-wrap: break-word; color: rgb(69, 69, 69);"><span style="word-wrap: break-word; font-size: 16px;">time.Now().Format(&quot;2006-01-02 15:04:05&quot;)<br style="word-wrap: break-word;" />
</span></span></div>
<div align="left" style="font-size: 14px; line-height: 1.7em; background-color: rgb(254, 254, 254); word-wrap: break-word; color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif;"><span style="word-wrap: break-word; color: rgb(69, 69, 69);"><span style="word-wrap: break-word; font-size: 16px;">time.Now().Format(&quot;2006-01-02&quot;)<br style="word-wrap: break-word;" />
</span></span></div>
<div align="left" style="font-size: 14px; line-height: 1.7em; background-color: rgb(254, 254, 254); word-wrap: break-word; color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif;"><span style="word-wrap: break-word; color: rgb(69, 69, 69);"><span style="word-wrap: break-word; font-size: 16px;">时间戳格式化到string</span></span></div>
<div align="left" style="font-size: 14px; line-height: 1.7em; background-color: rgb(254, 254, 254); word-wrap: break-word; color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif;"><span style="word-wrap: break-word; color: rgb(69, 69, 69);"><span style="word-wrap: break-word; font-size: 16px;">str_time := time.Unix(1389058332, 0).Format(&quot;2006-01-02 15:04:05&quot;)<br style="word-wrap: break-word;" />
</span></span></div>
<div align="left" style="font-size: 14px; line-height: 1.7em; background-color: rgb(254, 254, 254); word-wrap: break-word; color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif;"><span style="word-wrap: break-word; color: rgb(69, 69, 69);"><span style="word-wrap: break-word; font-size: 16px;">string 转化到 时间</span></span></div>
<div align="left" style="font-size: 14px; line-height: 1.7em; background-color: rgb(254, 254, 254); word-wrap: break-word; color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif;"><span style="word-wrap: break-word; color: rgb(69, 69, 69);"><span style="word-wrap: break-word; font-size: 16px;"><br style="word-wrap: break-word;" />
</span></span></div>
<div align="left" style="font-size: 14px; line-height: 1.7em; background-color: rgb(254, 254, 254); word-wrap: break-word; color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif;"><span style="word-wrap: break-word; color: rgb(69, 69, 69);"><span style="word-wrap: break-word; font-size: 16px;">以上是时间转化 接下来是总会用到的特殊事件</span></span></div>
<div align="left" style="font-size: 14px; line-height: 1.7em; background-color: rgb(254, 254, 254); word-wrap: break-word; color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif;"><span style="word-wrap: break-word; color: rgb(69, 69, 69);"><span style="word-wrap: break-word; font-size: 16px;">现在时间 time.Now()</span></span></div>
<div align="left" style="font-size: 14px; line-height: 1.7em; background-color: rgb(254, 254, 254); word-wrap: break-word; color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif;"><span style="word-wrap: break-word; color: rgb(69, 69, 69);"><span style="word-wrap: break-word; font-size: 16px;">今天00:00:00</span></span></div>
<div align="left" style="font-size: 14px; line-height: 1.7em; background-color: rgb(254, 254, 254); word-wrap: break-word; color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif;"><span style="word-wrap: break-word; color: rgb(69, 69, 69);"><span style="word-wrap: break-word; font-size: 16px;">now := time.Now()</span></span></div>
<div align="left" style="font-size: 14px; line-height: 1.7em; background-color: rgb(254, 254, 254); word-wrap: break-word; color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif;"><span style="word-wrap: break-word; color: rgb(69, 69, 69);"><span style="word-wrap: break-word; font-size: 16px;">year, month, day := now.Date()</span></span></div>
<div align="left" style="font-size: 14px; line-height: 1.7em; background-color: rgb(254, 254, 254); word-wrap: break-word; color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif;"><span style="word-wrap: break-word; color: rgb(69, 69, 69);"><span style="word-wrap: break-word; font-size: 16px;">today_str := fmt.Sprintf(&quot;%d-%d-%d 00:00:00&quot;, year, month, day)</span></span></div>
<div align="left" style="font-size: 14px; line-height: 1.7em; background-color: rgb(254, 254, 254); word-wrap: break-word; color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif;"><span style="word-wrap: break-word; color: rgb(69, 69, 69);"><span style="word-wrap: break-word; font-size: 16px;">today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)<br style="word-wrap: break-word;" />
</span></span></div>
<div align="left" style="font-size: 14px; line-height: 1.7em; background-color: rgb(254, 254, 254); word-wrap: break-word; color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif;"><span style="word-wrap: break-word; color: rgb(69, 69, 69);"><span style="word-wrap: break-word; font-size: 16px;">明天00:00:00</span></span></div>
<div align="left" style="font-size: 14px; line-height: 1.7em; background-color: rgb(254, 254, 254); word-wrap: break-word; color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif;"><span style="word-wrap: break-word; color: rgb(69, 69, 69);"><span style="word-wrap: break-word; font-size: 16px;">tomorrow := time.Now().Add(24*time.Hour)</span></span></div>
<br style="text-align: start; background-color: rgb(254, 254, 254); word-wrap: break-word; color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif; font-size: 14px;" />
<div align="left" style="font-size: 14px; line-height: 1.7em; background-color: rgb(254, 254, 254); word-wrap: break-word; color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif;"><span style="word-wrap: break-word; color: rgb(69, 69, 69);"><span style="word-wrap: break-word; font-size: 16px;">year, month, day := now.Date()</span></span></div>
<div align="left" style="font-size: 14px; line-height: 1.7em; background-color: rgb(254, 254, 254); word-wrap: break-word; color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif;"><span style="word-wrap: break-word; color: rgb(69, 69, 69);"><span style="word-wrap: break-word; font-size: 16px;">tomorrow_str := fmt.Sprintf(&quot;%d-%d-%d 00:00:00&quot;, year, month, day)</span></span></div>
<div align="left" style="font-size: 14px; line-height: 1.7em; background-color: rgb(254, 254, 254); word-wrap: break-word; color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif;"><span style="word-wrap: break-word; color: rgb(69, 69, 69);"><span style="word-wrap: break-word; font-size: 16px;">tomorrow_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)</span></span></div>
<br style="text-align: start; background-color: rgb(254, 254, 254); word-wrap: break-word; color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif; font-size: 14px;" />
<div align="left" style="font-size: 14px; line-height: 1.7em; background-color: rgb(254, 254, 254); word-wrap: break-word; color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif;"><span style="word-wrap: break-word; color: rgb(69, 69, 69);"><span style="word-wrap: break-word; font-size: 16px;">时间比较</span></span></div>
<div align="left" style="font-size: 14px; line-height: 1.7em; background-color: rgb(254, 254, 254); word-wrap: break-word; color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif;"><span style="word-wrap: break-word; color: rgb(69, 69, 69);"><span style="word-wrap: break-word; font-size: 16px;">可以转化为时间戳比较</span></span></div>
<div align="left" style="font-size: 14px; line-height: 1.7em; background-color: rgb(254, 254, 254); word-wrap: break-word; color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif;"><span style="word-wrap: break-word; color: rgb(69, 69, 69);"><span style="word-wrap: break-word; font-size: 16px;">也可以用before 等来比较</span></span></div>
<br style="text-align: start; background-color: rgb(254, 254, 254); word-wrap: break-word; color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif; font-size: 14px;" />
<br style="text-align: start; background-color: rgb(254, 254, 254); word-wrap: break-word; color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif; font-size: 14px;" />
<span style="text-align: start; background-color: rgb(254, 254, 254); color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif; font-size: 14px;">// 补充 时间戳转化&nbsp;</span><span style="color: rgb(51, 51, 51); font-family: &quot;Helvetica Neue&quot;, Helvetica, Tahoma, Arial, STXihei, &quot;Microsoft YaHei&quot;, 寰蒋闆呴粦, sans-serif; text-align: start; background-color: rgb(254, 254, 254);">&nbsp;</span><br style="text-align: start; background-color: rgb(254, 254, 254); word-wrap: break-word; color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif; font-size: 14px;" />
<span style="text-align: start; background-color: rgb(254, 254, 254); color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif; font-size: 14px;">// 例子 前一天这个时候 86400是24小时的秒数</span><span style="color: rgb(51, 51, 51); font-family: &quot;Helvetica Neue&quot;, Helvetica, Tahoma, Arial, STXihei, &quot;Microsoft YaHei&quot;, 寰蒋闆呴粦, sans-serif; text-align: start; background-color: rgb(254, 254, 254);">&nbsp;</span><br style="text-align: start; background-color: rgb(254, 254, 254); word-wrap: break-word; color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif; font-size: 14px;" />
<span style="text-align: start; background-color: rgb(254, 254, 254); color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif; font-size: 14px;">fmt</span><span style="color: rgb(51, 51, 51); font-family: &quot;Helvetica Neue&quot;, Helvetica, Tahoma, Arial, STXihei, &quot;Microsoft YaHei&quot;, 寰蒋闆呴粦, sans-serif; text-align: start; background-color: rgb(254, 254, 254);">&nbsp;</span><span style="text-align: start; background-color: rgb(254, 254, 254); color: rgb(0, 0, 0); word-wrap: break-word; font-family: Tahoma, Helvetica, SimSun, sans-serif; font-size: 14px;">.</span><span style="color: rgb(51, 51, 51); font-family: &quot;Helvetica Neue&quot;, Helvetica, Tahoma, Arial, STXihei, &quot;Microsoft YaHei&quot;, 寰蒋闆呴粦, sans-serif; text-align: start; background-color: rgb(254, 254, 254);">&nbsp;</span><span style="text-align: start; background-color: rgb(254, 254, 254); color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif; font-size: 14px;">Println</span><span style="color: rgb(51, 51, 51); font-family: &quot;Helvetica Neue&quot;, Helvetica, Tahoma, Arial, STXihei, &quot;Microsoft YaHei&quot;, 寰蒋闆呴粦, sans-serif; text-align: start; background-color: rgb(254, 254, 254);">&nbsp;</span><span style="text-align: start; background-color: rgb(254, 254, 254); color: rgb(0, 0, 0); word-wrap: break-word; font-family: Tahoma, Helvetica, SimSun, sans-serif; font-size: 14px;">(</span><span style="color: rgb(51, 51, 51); font-family: &quot;Helvetica Neue&quot;, Helvetica, Tahoma, Arial, STXihei, &quot;Microsoft YaHei&quot;, 寰蒋闆呴粦, sans-serif; text-align: start; background-color: rgb(254, 254, 254);">&nbsp;</span><span style="text-align: start; background-color: rgb(254, 254, 254); color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif; font-size: 14px;">time</span><span style="color: rgb(51, 51, 51); font-family: &quot;Helvetica Neue&quot;, Helvetica, Tahoma, Arial, STXihei, &quot;Microsoft YaHei&quot;, 寰蒋闆呴粦, sans-serif; text-align: start; background-color: rgb(254, 254, 254);">&nbsp;</span><span style="text-align: start; background-color: rgb(254, 254, 254); color: rgb(0, 0, 0); word-wrap: break-word; font-family: Tahoma, Helvetica, SimSun, sans-serif; font-size: 14px;">.</span><span style="color: rgb(51, 51, 51); font-family: &quot;Helvetica Neue&quot;, Helvetica, Tahoma, Arial, STXihei, &quot;Microsoft YaHei&quot;, 寰蒋闆呴粦, sans-serif; text-align: start; background-color: rgb(254, 254, 254);">&nbsp;</span><span style="text-align: start; background-color: rgb(254, 254, 254); color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif; font-size: 14px;">Unix</span><span style="color: rgb(51, 51, 51); font-family: &quot;Helvetica Neue&quot;, Helvetica, Tahoma, Arial, STXihei, &quot;Microsoft YaHei&quot;, 寰蒋闆呴粦, sans-serif; text-align: start; background-color: rgb(254, 254, 254);">&nbsp;</span><span style="text-align: start; background-color: rgb(254, 254, 254); color: rgb(0, 0, 0); word-wrap: break-word; font-family: Tahoma, Helvetica, SimSun, sans-serif; font-size: 14px;">(</span><span style="color: rgb(51, 51, 51); font-family: &quot;Helvetica Neue&quot;, Helvetica, Tahoma, Arial, STXihei, &quot;Microsoft YaHei&quot;, 寰蒋闆呴粦, sans-serif; text-align: start; background-color: rgb(254, 254, 254);">&nbsp;</span><span style="text-align: start; background-color: rgb(254, 254, 254); color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif; font-size: 14px;">time</span><span style="color: rgb(51, 51, 51); font-family: &quot;Helvetica Neue&quot;, Helvetica, Tahoma, Arial, STXihei, &quot;Microsoft YaHei&quot;, 寰蒋闆呴粦, sans-serif; text-align: start; background-color: rgb(254, 254, 254);">&nbsp;</span><span style="text-align: start; background-color: rgb(254, 254, 254); color: rgb(0, 0, 0); word-wrap: break-word; font-family: Tahoma, Helvetica, SimSun, sans-serif; font-size: 14px;">.</span><span style="color: rgb(51, 51, 51); font-family: &quot;Helvetica Neue&quot;, Helvetica, Tahoma, Arial, STXihei, &quot;Microsoft YaHei&quot;, 寰蒋闆呴粦, sans-serif; text-align: start; background-color: rgb(254, 254, 254);">&nbsp;</span><span style="text-align: start; background-color: rgb(254, 254, 254); color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif; font-size: 14px;">Now</span><span style="color: rgb(51, 51, 51); font-family: &quot;Helvetica Neue&quot;, Helvetica, Tahoma, Arial, STXihei, &quot;Microsoft YaHei&quot;, 寰蒋闆呴粦, sans-serif; text-align: start; background-color: rgb(254, 254, 254);">&nbsp;</span><span style="text-align: start; background-color: rgb(254, 254, 254); color: rgb(0, 0, 0); word-wrap: break-word; font-family: Tahoma, Helvetica, SimSun, sans-serif; font-size: 14px;">().</span><span style="color: rgb(51, 51, 51); font-family: &quot;Helvetica Neue&quot;, Helvetica, Tahoma, Arial, STXihei, &quot;Microsoft YaHei&quot;, 寰蒋闆呴粦, sans-serif; text-align: start; background-color: rgb(254, 254, 254);">&nbsp;</span><span style="text-align: start; background-color: rgb(254, 254, 254); color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif; font-size: 14px;">Unix</span><span style="color: rgb(51, 51, 51); font-family: &quot;Helvetica Neue&quot;, Helvetica, Tahoma, Arial, STXihei, &quot;Microsoft YaHei&quot;, 寰蒋闆呴粦, sans-serif; text-align: start; background-color: rgb(254, 254, 254);">&nbsp;</span><span style="text-align: start; background-color: rgb(254, 254, 254); color: rgb(0, 0, 0); word-wrap: break-word; font-family: Tahoma, Helvetica, SimSun, sans-serif; font-size: 14px;">()+</span><span style="color: rgb(51, 51, 51); font-family: &quot;Helvetica Neue&quot;, Helvetica, Tahoma, Arial, STXihei, &quot;Microsoft YaHei&quot;, 寰蒋闆呴粦, sans-serif; text-align: start; background-color: rgb(254, 254, 254);">&nbsp;</span><span style="text-align: start; background-color: rgb(254, 254, 254); color: rgb(128, 0, 128); word-wrap: break-word; font-family: Tahoma, Helvetica, SimSun, sans-serif; font-size: 14px;">86400</span><span style="color: rgb(51, 51, 51); font-family: &quot;Helvetica Neue&quot;, Helvetica, Tahoma, Arial, STXihei, &quot;Microsoft YaHei&quot;, 寰蒋闆呴粦, sans-serif; text-align: start; background-color: rgb(254, 254, 254);">&nbsp;</span><span style="text-align: start; background-color: rgb(254, 254, 254); color: rgb(0, 0, 0); word-wrap: break-word; font-family: Tahoma, Helvetica, SimSun, sans-serif; font-size: 14px;">,</span><span style="color: rgb(51, 51, 51); font-family: &quot;Helvetica Neue&quot;, Helvetica, Tahoma, Arial, STXihei, &quot;Microsoft YaHei&quot;, 寰蒋闆呴粦, sans-serif; text-align: start; background-color: rgb(254, 254, 254);">&nbsp;</span><span style="text-align: start; background-color: rgb(254, 254, 254); color: rgb(192, 192, 192); word-wrap: break-word; font-family: Tahoma, Helvetica, SimSun, sans-serif; font-size: 14px;">&nbsp;</span><span style="color: rgb(51, 51, 51); font-family: &quot;Helvetica Neue&quot;, Helvetica, Tahoma, Arial, STXihei, &quot;Microsoft YaHei&quot;, 寰蒋闆呴粦, sans-serif; text-align: start; background-color: rgb(254, 254, 254);">&nbsp;</span><span style="text-align: start; background-color: rgb(254, 254, 254); color: rgb(128, 0, 128); word-wrap: break-word; font-family: Tahoma, Helvetica, SimSun, sans-serif; font-size: 14px;">0</span><span style="color: rgb(51, 51, 51); font-family: &quot;Helvetica Neue&quot;, Helvetica, Tahoma, Arial, STXihei, &quot;Microsoft YaHei&quot;, 寰蒋闆呴粦, sans-serif; text-align: start; background-color: rgb(254, 254, 254);">&nbsp;</span><span style="text-align: start; background-color: rgb(254, 254, 254); color: rgb(0, 0, 0); word-wrap: break-word; font-family: Tahoma, Helvetica, SimSun, sans-serif; font-size: 14px;">).</span><span style="color: rgb(51, 51, 51); font-family: &quot;Helvetica Neue&quot;, Helvetica, Tahoma, Arial, STXihei, &quot;Microsoft YaHei&quot;, 寰蒋闆呴粦, sans-serif; text-align: start; background-color: rgb(254, 254, 254);">&nbsp;</span><span style="text-align: start; background-color: rgb(254, 254, 254); color: rgb(68, 68, 68); font-family: Tahoma, Helvetica, SimSun, sans-serif; font-size: 14px;">Format</span><span style="color: rgb(51, 51, 51); font-family: &quot;Helvetica Neue&quot;, Helvetica, Tahoma, Arial, STXihei, &quot;Microsoft YaHei&quot;, 寰蒋闆呴粦, sans-serif; text-align: start; background-color: rgb(254, 254, 254);">&nbsp;</span><span style="text-align: start; background-color: rgb(254, 254, 254); color: rgb(0, 0, 0); word-wrap: break-word; font-family: Tahoma, Helvetica, SimSun, sans-serif; font-size: 14px;">(</span><span style="color: rgb(51, 51, 51); font-family: &quot;Helvetica Neue&quot;, Helvetica, Tahoma, Arial, STXihei, &quot;Microsoft YaHei&quot;, 寰蒋闆呴粦, sans-serif; text-align: start; background-color: rgb(254, 254, 254);">&nbsp;</span><span style="text-align: start; background-color: rgb(254, 254, 254); color: rgb(0, 128, 0); word-wrap: break-word; font-family: Tahoma, Helvetica, SimSun, sans-serif; font-size: 14px;">&quot;20060102&quot;</span><span style="color: rgb(51, 51, 51); font-family: &quot;Helvetica Neue&quot;, Helvetica, Tahoma, Arial, STXihei, &quot;Microsoft YaHei&quot;, 寰蒋闆呴粦, sans-serif; text-align: start; background-color: rgb(254, 254, 254);">&nbsp;</span><span style="text-align: start; background-color: rgb(254, 254, 254); color: rgb(0, 0, 0); word-wrap: break-word; font-family: Tahoma, Helvetica, SimSun, sans-serif; font-size: 14px;">))</span></div>
<div style="color: rgb(79, 79, 79); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, SimHei, Arial, SimSun; font-size: 16px;"><span style="text-align: start; background-color: rgb(254, 254, 254); color: rgb(0, 0, 0); word-wrap: break-word; font-family: Tahoma, Helvetica, SimSun, sans-serif; font-size: 14px;"><br />
</span></div>
<div style="color: rgb(79, 79, 79); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, SimHei, Arial, SimSun; font-size: 16px;"><span style="text-align: start; background-color: rgb(254, 254, 254); color: rgb(0, 0, 0); word-wrap: break-word; font-family: Tahoma, Helvetica, SimSun, sans-serif; font-size: 14px;">-------------------------</span></div>
<div style=""><span style="text-align: start; background-color: rgb(254, 254, 254); word-wrap: break-word;"><font face="Tahoma, Helvetica, SimSun, sans-serif">
<div style="">时间戳&nbsp;</div>
<div style="">当前时间戳</div>
<div style="">&nbsp;</div>
<div style="">fmt.Println(time.Now().Unix())</div>
<div style=""># 1389058332</div>
<div style="">str格式化时间</div>
<div style="">当前格式化时间</div>
<div style="">&nbsp;</div>
<div style="">fmt.Println(time.Now().Format(&quot;2006-01-02 15:04:05&quot;))&nbsp; // 这是个奇葩,必须是这个时间点, 据说是go诞生之日, 记忆方法:6-1-2-3-4-5</div>
<div style=""># 2014-01-07 09:42:20</div>
<div style="">时间戳转str格式化时间</div>
<div style="">&nbsp;</div>
<div style="">str_time := time.Unix(1389058332, 0).Format(&quot;2006-01-02 15:04:05&quot;)</div>
<div style="">fmt.Println(str_time)</div>
<div style=""># 2014-01-07 09:32:12</div>
<div style="">str格式化时间转时间戳</div>
<div style="">这个比较麻烦</div>
<div style="">&nbsp;</div>
<div style="">the_time := time.Date(2014, 1, 7, 5, 50, 4, 0, time.Local)</div>
<div style="">unix_time := the_time.Unix()</div>
<div style="">fmt.Println(unix_time)</div>
<div style=""># 389045004</div>
<div style="">还有一种方法,使用time.Parse</div>
<div style="">&nbsp;</div>
<div style="">the_time, err := time.Parse(&quot;2006-01-02 15:04:05&quot;, &quot;2014-01-08 09:04:41&quot;)</div>
<div style="">if err == nil {</div>
<div style="">&nbsp; &nbsp; &nbsp; &nbsp; unix_time := the_time.Unix()</div>
<div style=""><span style="white-space:pre">	</span>fmt.Println(unix_time)<span style="white-space:pre">		</span></div>
<div style="">}</div>
<div style=""># 1389171881</div>
</font></span></div>
<div style="color: rgb(79, 79, 79); font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, SimHei, Arial, SimSun; font-size: 16px;">&nbsp;</div>
</font></span></div>]]></description>
			<link>http://meisw.wdlinux.cn//show-1028-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-47-1.html">golang</category>
			<pubDate>2018-06-14 18:23</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-1025-1.html</guid>
			<title>Golang常用正则验证</title>
			<author>admin</author>
			<description><![CDATA[<p>&nbsp;package main</p>
<div>&nbsp;</div>
<div>import (</div>
<div>&nbsp; &nbsp; &quot;fmt&quot;</div>
<div>&nbsp; &nbsp; &quot;regexp&quot;</div>
<div>)</div>
<div>&nbsp;</div>
<div>var reg *regexp.Regexp</div>
<div>var pattern string</div>
<div>var source string</div>
<div>&nbsp;</div>
<div>func regexpMatch() {</div>
<div>&nbsp; &nbsp; //&nbsp; xy 匹配x y</div>
<div>&nbsp; &nbsp; // x|y&nbsp; 匹配x或者y 优先x</div>
<div>&nbsp; &nbsp; // source = &quot;asdfdsxxxyyfergsfasfxyfa&quot;</div>
<div>&nbsp; &nbsp; // pattern = `x|y|a`</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; //x* 匹配零个或者多个x,优先匹配多个</div>
<div>&nbsp; &nbsp; //x+ 匹配一个或者多个x，优先匹配多个</div>
<div>&nbsp; &nbsp; //x? 匹配零个或者一个x，优先匹配一个</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; //source = &quot;xxxxewexxxasdfdsxxxyyfergsfasfxyfa&quot;</div>
<div>&nbsp; &nbsp; //pattern = `x*`</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; // x{n,m} 匹配n个到m个x，优先匹配m个</div>
<div>&nbsp; &nbsp; // x{n,}&nbsp; 匹配n个到多个x，优先匹配更多</div>
<div>&nbsp; &nbsp; // x{n} 或者x{n}?&nbsp; 只匹配n个x</div>
<div>&nbsp; &nbsp; //source = &quot;xxxxxxxewexxxasdfdsxxxyyfergsfasfxyfa&quot;</div>
<div>&nbsp; &nbsp; //pattern = `x{4,}`</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; // x{n,m}? 匹配n个到m个x，优先匹配n个</div>
<div>&nbsp; &nbsp; // x{n,}?&nbsp; 匹配n个到多个x，优先匹配n个</div>
<div>&nbsp; &nbsp; // x*?&nbsp; &nbsp;匹配零个或者多个x，优先匹配0个</div>
<div>&nbsp; &nbsp; // x+?&nbsp; &nbsp;匹配一个或者多个x，优先匹配1个</div>
<div>&nbsp; &nbsp; // x??&nbsp; &nbsp;匹配零个或者一个x，优先匹配0个</div>
<div>&nbsp; &nbsp; //source = &quot;xxxxxxxewexxxasdfdsxxxyyfergsfasfxyfa&quot;</div>
<div>&nbsp; &nbsp; //pattern = `x??`</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; //[\d] 或者[^\D] 匹配数字</div>
<div>&nbsp; &nbsp; //[^\d]或者 [\D] 匹配非数字</div>
<div>&nbsp; &nbsp; //source = &quot;xx435ff5237yy6346fergsfasfxyfa&quot;</div>
<div>&nbsp; &nbsp; //pattern = `[\d]{3,}` //匹配3个或者更多个数字</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; //source = &quot;xx435ffGUTEYgjk52RYPHFY37yy6346ferg6987sfasfxyfa&quot;</div>
<div>&nbsp; &nbsp; //pattern = `[a-z]{3,}` //三个或者多个小写字母</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; //source = &quot;xx435ffGUTEYgjk52RYPHFY37yy6346ferg6987sfasfxyfa&quot;</div>
<div>&nbsp; &nbsp; //pattern = `[[:alpha:]]{5,}` //5个或者多个字母，相当于A-Za-z</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; //source = &quot;xx435,./$%(*(_&amp;jgshgs发个^$%ffG返回福hjh放假啊啥UTEYgjk52RYPHFY37yy6346ferg6987sfasfxyfa&quot;</div>
<div>&nbsp; &nbsp; //pattern = `[\p{Han}]+` //匹配连续的汉字</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; //source = &quot;13244820821HG74892109977HJA15200806084S11233240697hdgsfhah假发发货&quot;</div>
<div>&nbsp; &nbsp; //pattern = `1[3|5|7|8|][\d]{9}` //匹配电话号码</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; //source = &quot;132@12.comGKGk15@163.cn200806084S11233240697hdgsfhah假发发货&quot;</div>
<div>&nbsp; &nbsp; //pattern = `\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*` //匹配电子邮箱</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; //匹配用户名或者密码 `^[a-zA-Z0-9_-]{4,16}$`&nbsp; 字母或者数字开头，区分大小写，最短4位最长16位</div>
<div>&nbsp; &nbsp; //匹配IP地址1 `^$(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$`</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; //匹配IP地址2</div>
<div>&nbsp; &nbsp; //pattern = `((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)`</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; //匹配日期 年-月-日 `(\d{4}|\d{2})-((1[0-2])|(0?[1-9]))-(([12][0-9])|(3[01])|(0?[1-9]))`</div>
<div>&nbsp; &nbsp; //匹配日期 月-日-年&nbsp; `((1[0-2])|(0?[1-9]))/(([12][0-9])|(3[01])|(0?[1-9]))/(\d{4}|\d{2})`</div>
<div>&nbsp; &nbsp; //匹配时间 小时：分钟 24小时制 ` ((1|0?)[0-9]|2[0-3]):([0-5][0-9]) `</div>
<div>&nbsp; &nbsp; //匹配邮编&nbsp; `[1-9][\d]5`</div>
<div>&nbsp; &nbsp; //匹配URL `[a-zA-z]+://[^\s]*`</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; reg = regexp.MustCompile(pattern)</div>
<div>&nbsp; &nbsp; fmt.Printf(&quot;%s&quot;, reg.FindAllString(source, -1))</div>
<div>&nbsp;</div>
<div>}</div>
<div>func main() {</div>
<div>&nbsp; &nbsp; regexpMatch()</div>
<div>}</div>]]></description>
			<link>http://meisw.wdlinux.cn//show-1025-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-47-1.html">golang</category>
			<pubDate>2018-06-07 10:42</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-1024-1.html</guid>
			<title>几个常用的正则表达式</title>
			<author>admin</author>
			<description><![CDATA[<p>&nbsp;</p>
<pre class="prettyprint linenums prettyprinted"><ol class="linenums"><li class="L0"><span class="com">// 中国大陆手机号码正则匹配, 不是那么太精细</span></li><li class="L1"><span class="com">// 只要是 13,14,15,18 开头的 11 位数字就认为是中国手机号</span></li><li class="L2"><span class="pln">chinaMobilePattern </span><span class="pun">=</span><span class="pln"> </span><span class="str">`^1[3458][0-9]{9}$`</span></li><li class="L3"><span class="com">// 用户昵称的正则匹配, 合法的字符有 0-9, A-Z, a-z, _, 汉字</span></li><li class="L4"><span class="com">// 字符 '_' 只能出现在中间且不能重复, 如 &quot;__&quot;</span></li><li class="L5"><span class="pln">nicknamePattern </span><span class="pun">=</span><span class="pln"> </span><span class="str">`^[a-z0-9A-Z\p{Han}]+(_[a-z0-9A-Z\p{Han}]+)*$`</span></li><li class="L6"><span class="com">// 用户名的正则匹配, 合法的字符有 0-9, A-Z, a-z, _</span></li><li class="L7"><span class="com">// 第一个字母不能为 _, 0-9</span></li><li class="L8"><span class="com">// 最后一个字母不能为 _, 且 _ 不能连续</span></li><li class="L9"><span class="pln">namePattern </span><span class="pun">=</span><span class="pln"> </span><span class="str">`^[a-zA-Z][a-z0-9A-Z]*(_[a-z0-9A-Z]+)*$`</span></li><li class="L0"><span class="com">// 电子邮箱的正则匹配, 考虑到各个网站的 mail 要求不一样, 这里匹配比较宽松</span></li><li class="L1"><span class="com">// 邮箱用户名可以包含 0-9, A-Z, a-z, -, _, .</span></li><li class="L2"><span class="com">// 开头字母不能是 -, _, .</span></li><li class="L3"><span class="com">// 结尾字母不能是 -, _, .</span></li><li class="L4"><span class="com">// -, _, . 这三个连接字母任意两个不能连续, 如不能出现 --, __, .., -_, -., _.</span></li><li class="L5"><span class="com">// 邮箱的域名可以包含 0-9, A-Z, a-z, -</span></li><li class="L6"><span class="com">// 连接字符 - 只能出现在中间, 不能连续, 如不能 --</span></li><li class="L7"><span class="com">// 支持多级域名, x@y.z, x@y.z.w, x@x.y.z.w.e</span></li><li class="L8"><span class="pln">mailPattern </span><span class="pun">=</span><span class="pln"> </span><span class="str">`^[a-z0-9A-Z]+([\-_\.][a-z0-9A-Z]+)*@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)*\.)+[a-zA-Z]+$`</span></li></ol></pre>]]></description>
			<link>http://meisw.wdlinux.cn//show-1024-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-47-1.html">golang</category>
			<pubDate>2018-06-06 23:58</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-1022-1.html</guid>
			<title>golang 字符串转换为 json数据</title>
			<author>admin</author>
			<description><![CDATA[<div>package main</div>
<div>&nbsp;</div>
<div>import (</div>
<div>&nbsp; &nbsp; &quot;encoding/json&quot;</div>
<div>&nbsp; &nbsp; &quot;fmt&quot;</div>
<div>&nbsp; &nbsp; &quot;os&quot;</div>
<div>)</div>
<div>&nbsp;</div>
<div>type ConfigStruct struct {</div>
<div>&nbsp; &nbsp; Host&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string&nbsp; &nbsp;`json:&quot;host&quot;`</div>
<div>&nbsp; &nbsp; Port&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int&nbsp; &nbsp; &nbsp; `json:&quot;port&quot;`</div>
<div>&nbsp; &nbsp; AnalyticsFile&nbsp; &nbsp; &nbsp;string&nbsp; &nbsp;`json:&quot;analytics_file&quot;`</div>
<div>&nbsp; &nbsp; StaticFileVersion int&nbsp; &nbsp; &nbsp; `json:&quot;static_file_version&quot;`</div>
<div>&nbsp; &nbsp; StaticDir&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;string&nbsp; &nbsp;`json:&quot;static_dir&quot;`</div>
<div>&nbsp; &nbsp; TemplatesDir&nbsp; &nbsp; &nbsp; string&nbsp; &nbsp;`json:&quot;templates_dir&quot;`</div>
<div>&nbsp; &nbsp; SerTcpSocketHost&nbsp; string&nbsp; &nbsp;`json:&quot;serTcpSocketHost&quot;`</div>
<div>&nbsp; &nbsp; SerTcpSocketPort&nbsp; int&nbsp; &nbsp; &nbsp; `json:&quot;serTcpSocketPort&quot;`</div>
<div>&nbsp; &nbsp; Fruits&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; []string `json:&quot;fruits&quot;`</div>
<div>}</div>
<div>&nbsp;</div>
<div>type Other struct {</div>
<div>&nbsp; &nbsp; SerTcpSocketHost string&nbsp; &nbsp;`json:&quot;serTcpSocketHost&quot;`</div>
<div>&nbsp; &nbsp; SerTcpSocketPort int&nbsp; &nbsp; &nbsp; `json:&quot;serTcpSocketPort&quot;`</div>
<div>&nbsp; &nbsp; Fruits&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[]string `json:&quot;fruits&quot;`</div>
<div>}</div>
<div>&nbsp;</div>
<div>func main() {&nbsp;</div>
<div>&nbsp; &nbsp; jsonStr := `{&quot;host&quot;: &quot;http://localhost:9090&quot;,&quot;port&quot;: 9090,&quot;analytics_file&quot;: &quot;&quot;,&quot;static_file_version&quot;: 1,&quot;static_dir&quot;: &quot;E:/Project/goTest/src/&quot;,&quot;templates_dir&quot;: &quot;E:/Project/goTest/src/templates/&quot;,&quot;serTcpSocketHost&quot;: &quot;:12340&quot;,&quot;serTcpSocketPort&quot;: 12340,&quot;fruits&quot;: [&quot;apple&quot;, &quot;peach&quot;]}`</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; //json str 转map</div>
<div>&nbsp; &nbsp; var dat map[string]interface{}</div>
<div>&nbsp; &nbsp; if err := json.Unmarshal([]byte(jsonStr), &amp;dat); err == nil {</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; fmt.Println(&quot;==============json str 转map=======================&quot;)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; fmt.Println(dat)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; fmt.Println(dat[&quot;host&quot;])</div>
<div>&nbsp; &nbsp; }</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; //json str 转struct</div>
<div>&nbsp; &nbsp; var config ConfigStruct</div>
<div>&nbsp; &nbsp; if err := json.Unmarshal([]byte(jsonStr), &amp;config); err == nil {</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; fmt.Println(&quot;================json str 转struct==&quot;)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; fmt.Println(config)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; fmt.Println(config.Host)</div>
<div>&nbsp; &nbsp; }</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; //json str 转struct(部份字段)</div>
<div>&nbsp; &nbsp; var part Other</div>
<div>&nbsp; &nbsp; if err := json.Unmarshal([]byte(jsonStr), &amp;part); err == nil {</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; fmt.Println(&quot;================json str 转struct==&quot;)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; fmt.Println(part)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; fmt.Println(part.SerTcpSocketPort)</div>
<div>&nbsp; &nbsp; }</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; //struct 到json str</div>
<div>&nbsp; &nbsp; if b, err := json.Marshal(config); err == nil {</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; fmt.Println(&quot;================struct 到json str==&quot;)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; fmt.Println(string(b))</div>
<div>&nbsp; &nbsp; }</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; //map 到json str</div>
<div>&nbsp; &nbsp; fmt.Println(&quot;================map 到json str=====================&quot;)</div>
<div>&nbsp; &nbsp; enc := json.NewEncoder(os.Stdout)</div>
<div>&nbsp; &nbsp; enc.Encode(dat)</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; //array 到 json str</div>
<div>&nbsp; &nbsp; arr := []string{&quot;hello&quot;, &quot;apple&quot;, &quot;python&quot;, &quot;golang&quot;, &quot;base&quot;, &quot;peach&quot;, &quot;pear&quot;}</div>
<div>&nbsp; &nbsp; lang, err := json.Marshal(arr)</div>
<div>&nbsp; &nbsp; if err == nil {</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; fmt.Println(&quot;================array 到 json str==&quot;)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; fmt.Println(string(lang))</div>
<div>&nbsp; &nbsp; }</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; //json 到 []string</div>
<div>&nbsp; &nbsp; var wo []string</div>
<div>&nbsp; &nbsp; if err := json.Unmarshal(lang, &amp;wo); err == nil {</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; fmt.Println(&quot;================json 到 []string==&quot;)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; fmt.Println(wo)</div>
<div>&nbsp; &nbsp; }</div>
<div>}</div>]]></description>
			<link>http://meisw.wdlinux.cn//show-1022-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-47-1.html">golang</category>
			<pubDate>2018-06-05 11:41</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-1020-1.html</guid>
			<title>文件上传，断点续传</title>
			<author>admin</author>
			<description><![CDATA[<p>&nbsp;文件下载之断点续传（客户端与服务端的实现）</p>
<div>https://www.cnblogs.com/zhaopei/p/download.html</div>
<div>&nbsp;</div>
<div>文件各种上传，离不开的表单</div>
<div>http://www.cnblogs.com/zhaopei/p/upload.html</div>
<div>&nbsp;</div>
<div>
<div>Golang实现断点续传</div>
<div>https://www.cnblogs.com/7explore-share/p/8111720.html</div>
<div>&nbsp;</div>
<div>阿里云上传文件</div>
<div>https://helpcdn.aliyun.com/document_detail/32147.html</div>
<div>&nbsp;</div>
<div>
<h1 style="box-sizing: border-box; font-size: 24px; margin: 0px 0px 10px; font-family: &quot;Source Sans Pro&quot;, Calibri, Candara, Arial, sans-serif; font-weight: 500; line-height: 36px; color: rgb(51, 51, 51); padding: 0px;">Go语言实现文件断点续传功能&mdash;resumable file uploads</h1>
</div>
<div>
<ul style="margin-bottom: 10.5px; box-sizing: border-box; font-family: &quot;Helvetica Neue&quot;, &quot;Luxi Sans&quot;, &quot;DejaVu Sans&quot;, Tahoma, &quot;Hiragino Sans GB&quot;, &quot;Microsoft Yahei&quot;, sans-serif;">
    <li style="box-sizing: border-box;"><a href="https://github.com/tus/tusd" style="color: rgb(102, 102, 102); box-sizing: border-box; background: transparent; text-decoration-line: none; word-break: break-all; font-weight: 700;">源码</a></li>
    <li style="box-sizing: border-box;"><a href="http://www.tus.io/protocols/resumable-upload.html" target="_blank" style="color: rgb(102, 102, 102); box-sizing: border-box; background: transparent; text-decoration-line: none; word-break: break-all; font-weight: 700;">协议：tus resumable upload protocol</a></li>
</ul>
</div>
</div>
<div>&nbsp;</div>
<div>
<h1 class="csdn_top" style="font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, SimHei, Arial, SimSun; margin: 0px; padding: 0px 29px; box-sizing: border-box; word-break: break-all; word-wrap: break-word; color: rgb(44, 48, 51); font-size: 24px; line-height: 38px;">HTTP 断点续传（分块传输）</h1>
</div>
<div>https://blog.csdn.net/liang19890820/article/details/53215087</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>
<div>HTTP Range 请求</div>
<div>HTTP Range请求允许服务器向客户端发送HTTP消息体的一部分数据。Partial Requests在使用比较大的网络媒体文件或者在下载文件时提供暂停和恢复功能时很有用。</div>
<div>这也是下载时实现HTTP断点续传的一个关键。</div>
<div>&nbsp;</div>
<div>HTTP 206 (Partial Content)</div>
<div>如果服务器能返回HTTP 206请求，我们就知道它能够支持Range request.</div>
<div># curl -I https://www.baidu.com/ -H &quot;Range: bytes=0-&quot;</div>
</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>下载续传，一般WEB服务器，如nginx,apache,iis已支付，只在客户端实现即可</div>
<div>上传续传，也叫分片上传，需要分别在服务端，客户端实现</div>
<div>服务端针对分片的处理，获取当前的分片，每个分片上传保存，然后将分片合并</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>---</div>
<div>一些思路</div>
<div>
<div>提供一个思路，上传前先往数据库插入一条数据。数据包含文件要存的路径、文件名（用GUID命名，防止同名文件冲突）、文件MD5（用来识别下次续传和秒传）、临时文件块存放路径、文件是否完整上传成功等信息。</div>
<div>然后如果我们断网后再传，首先获取文件MD5值，看数据库里面有没上传完成的文件，如果有就实现秒传。如果没有，看是不是有上传了部分的。如果有接着传，如果没有则重新传一个新的文件。</div>
</div>
<div>&nbsp;</div>]]></description>
			<link>http://meisw.wdlinux.cn//show-1020-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-47-1.html">golang</category>
			<pubDate>2018-04-17 18:06</pubDate>
		</item>
	</channel>
</rss>
