<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
    <channel>
        <title>Golang - Tag - HEJTAO</title>
        <link>https://hejtao.netlify.app/tags/golang/</link>
        <description>Golang - Tag - HEJTAO</description>
        <generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Mon, 02 Oct 2023 00:00:00 &#43;0000</lastBuildDate><atom:link href="https://hejtao.netlify.app/tags/golang/" rel="self" type="application/rss+xml" /><item>
    <title>Concurrency in Go</title>
    <link>https://hejtao.netlify.app/posts/cs-concurrency/</link>
    <pubDate>Mon, 02 Oct 2023 00:00:00 &#43;0000</pubDate>
    <author>HEJTAO.COM</author>
    <guid>https://hejtao.netlify.app/posts/cs-concurrency/</guid>
    <description><![CDATA[Mutex const ( mutexLocked = 1 &lt;&lt; iota mutexWoken mutexStarving mutexWaiterShift = iota starvationThresholdNs = 1e6 ) // MSB 29: number of waiters // LSB 3: // starving(100) // woken(010) // locked(001) type Mutex struct { state int32 sema uint32 } Unlock competitive wakeup handoff wakeup func (m *Mutex) Unlock() { new := atomic.AddInt32(&amp;m.state, -mutexLocked) if new != 0 { m.unlockSlow(new) } } func (m *Mutex) unlockSlow(new int32) { if (new+mutexLocked)&amp;mutexLocked == 0 { fatal(&#34;sync: unlock of unlocked mutex&#34;) } if new&amp;mutexStarving == 0 { old := new for { // If there are no waiters or a goroutine has already // been woken or grabbed the lock, no need to wake anyone.]]></description>
</item>
<item>
    <title>Sign and Verify with Go</title>
    <link>https://hejtao.netlify.app/posts/cs-signature/</link>
    <pubDate>Wed, 14 Sep 2022 00:00:00 &#43;0000</pubDate>
    <author>HEJTAO.COM</author>
    <guid>https://hejtao.netlify.app/posts/cs-signature/</guid>
    <description><![CDATA[func GetSignature(encodedPriKey, rawMsg string) (string, error) { rawPriKey, err := base64.StdEncoding.DecodeString(encodedPriKey) if err != nil { return &#34;&#34;, err } // key block, _ := pem.Decode(rawPriKey) if block == nil { return &#34;&#34;, errors.New(&#34;ssh: no key found&#34;) } priKey, err := x509.ParsePKCS1PrivateKey(block.Bytes) if err != nil { return &#34;&#34;, err } // msg sha := sha256.New() sha.Write([]byte(rawMsg)) msg := sha.Sum(nil) signature, err := rsa.SignPSS(rand.Reader, priKey, crypto.SHA256, msg, nil) if err !]]></description>
</item>
<item>
    <title>Golang Notes</title>
    <link>https://hejtao.netlify.app/posts/cs-golang/</link>
    <pubDate>Mon, 20 Aug 2018 00:00:00 &#43;0000</pubDate>
    <author>HEJTAO.COM</author>
    <guid>https://hejtao.netlify.app/posts/cs-golang/</guid>
    <description><![CDATA[在 Ubuntu 安装: &gt;cd ~ &gt;wget https://dl.google.com/go/go1.11.2.linux-amd64.tar.gz &gt;tar -C /usr/local -xzf go1.11.2.linux-amd64.tar.gz // 解压到得到的 go 目录，放到 /usr/local 目录下 &gt;vim .bashrc // 写入以下内容 export GOPATH=~/hejtao/go_projects export GOROOT=/usr/local/go export GOBIN=$GOROOT/bin export PATH=$PATH:$GOBIN &gt;source .bashrc 更新依赖 go mod edit -replace=google.golang.org/grpc=github.com/grpc/grpc-go@latest go mod tidy go get -u github.com/grpc/grpc-go@latest GROM db.Where(models.Balance{ WalletAddress: &#34;xxx&#34;, ChainId: 666, }).Attrs(map[string]any{ &#34;balance&#34;: 888, }).Assign(map[string]any{ &#34;balance&#34;: gorm.Expr(&#34;Balance - ?&#34;, 5), }).FirstOrCreate(&amp;models.Balance{}) // 存在就 balance - 5 // 不存在就创建 {xxx, 666, 888} // struct 可以换成 map 数据类型: 基本类型： 数值 整型：int； int8； int16； int32(rune，Unicode)； int64； uint； uint8(byte)； uint16； uint32； uint64； uintptr int, uint, uintptr 在 32 位系统上是 32 位，在 64 位 系统上是 64 位 浮点型：float32； float64 复数型：complex64； complex128 字符串：使用双引号 &quot;a&quot; 布尔: true； false 常量：三种基本类型 在 if 语句中，若检验条件为 i &gt;= 0，则 i 的类型不宜为 uint 型（uint 数据始终 &gt;= 0）。尽管内置函数 len() 返回值是非负整数，但它际返回 int 型，]]></description>
</item>
</channel>
</rss>
