时间
https://www.cnblogs.com/followyou/p/12187949.html
error
https://www.cnblogs.com/followyou/p/12185514.html
断言
https://www.cnblogs.com/followyou/p/12185509.html
定义函数类型
type ExposureQualityService interface {
}
type NewExposureQualityServiceFunc func() ExposureQualityService
格式转换
https://www.cnblogs.com/followyou/p/12194128.html
打断点
fmt.Println(exposureData)
os.Exit(1)
休眠
func Sleep(d Duration)
const (
Nanosecond Duration = 1
Microsecond = 1000 * Nanosecond
Millisecond = 1000 * Microsecond
Second = 1000 * Millisecond
Minute = 60 * Second
Hour = 60 * Minute
)
urlencode
- 字符串
package main
import (
"fmt"
"net/url"
)
func main() {
query := "Hellö Wörld@Golang"
fmt.Println(url.QueryEscape(query))
}
- 多个参数
package main
import (
"fmt"
"net/url"
)
func main() {
params := url.Values{}
params.Add("name", "@Rajeev")
params.Add("phone", "+919999999999")
fmt.Println(params.Encode())
}
- 编码路径
package main
import (
"fmt"
"net/url"
)
func main() {
path := "path with?reserved+characters"
fmt.Println(url.PathEscape(path))
}
// Output
// path%20with%3Freserved+characters
解码参考 https://www.urldecoder.io/golang/
去除首尾空格
package main
import (
"fmt"
"strings"
)
func main() {
str := " hello world! "
str = strings.TrimSpace(str)
fmt.Println(str)
}
字符串截取
str := "oeryoqpqpqepqw"
content = str[1:10]
fmt.println(content)
ip转number
func Ip2long(ip string) int64 {
var cip net.IP
cip = []byte(ip)
// ipv4
if cip.To4() != nil {
num, _ := exnet.IP2Long(cip)
return int64(num)
} else {
bigint := ipv6ToInt(ip)
return bigint
}
}
func ipv6ToInt(ip string) int64 {
IPv6Int := big.NewInt(0)
IPv6Int.SetBytes(net.ParseIP(ip).To4())
return IPv6Int.Int64()
}
go test
显示单元测试详细信息且指定测试方法
go test -v data-structure/heap/btree_heap.go data-structure/heap/btree_heap_test.go -test.run TestHeap_Replace
Go 随机数
s := rand.NewSource(time.Now().UnixNano())
token := rand.New(s).Intn(1000000)