西维蜀黍

【Golang】同步机制 - WaitGroup

Usage

To wait for multiple goroutines to finish, we can use a wait group.

This is the function we’ll run in every goroutine. Note that a WaitGroup must be passed to functions by pointer.

On return, notify the WaitGroup that we’re done.

package main

import (
    "fmt"
    "sync"
    "time"
)

func worker(id int, wg *sync.WaitGroup) {

    defer wg.Done()

    fmt.Printf("Worker %d starting\n", id)

    time.Sleep(time.Second)
    fmt.Printf("Worker %d done\n", id)
}

func main() {

    var wg sync.WaitGroup

    for i := 1; i <= 5; i++ {
        wg.Add(1)
        // Launch several goroutines and increment the WaitGroup counter for each.
        go worker(i, &wg)
    }
		
    // Block until the WaitGroup counter goes back to 0; all the workers notified they’re done.
    wg.Wait()
}
  ...


【Linux】命令 - rename

Installation

$ brew install rename
  ...


【Linux】命令 - rm

rm -f - force - 强行删除

Attempt to remove the files without prompting for confirmation, regardless of the file’s permissions. If the file does not exist, do not display a diagnostic message or modify the exit status to reflect an error. The -f option overrides any previous -i options.

rm -d - directory - 删除文件夹

Attempt to remove directories as well as other types of files.

  ...


【Golang】依赖 - Checksum Mismatch

Context

执行 go mod tidy 报错

$ go mod tidy
go: verifying github.com/docker/docker@v1.13.1: checksum mismatch

Expect (go version go1.12.9 darwin/amd64):

$ go mod tidy -v
go: downloading github.com/panjf2000/ants v1.2.0
go: extracting github.com/panjf2000/ants v1.2.0

Actual (go version go1.13 darwin/amd64)

$ go mod tidy -v
verifying github.com/panjf2000/ants@v1.2.0: checksum mismatch
        downloaded: h1:Ufw4aDz9RqH1RVblx2W9L9Uv5vSX5apbX5+peR7LQ5k=
        sum.golang.org: h1:pMQ1/XpSgnWx3ro4y1xr/uA3jXUsTuAaU3Dm0JjwggE=

SECURITY ERROR
This download does NOT match the one reported by the checksum server.
The bits may have been replaced on the origin server, or an attacker may
have intercepted the download attempt.

For more information, see 'go help module-auth'.
  ...


【hugo】hugo 博客加载速度优化

Background

在将博客从 hexo 迁移到 hugo 下之后,顺便把使用的 CDN 从 GitHub 迁到了 AWS S3,再测了一下速度(via https://www.uptrends.com/tools/cdn-performance-check):

看起来速度还可以。

  ...