Skip to content

Instantly share code, notes, and snippets.

octo tangx

Block or report user

Report or block tangx

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@tangx
tangx / gochannel.go
Created Nov 19, 2019
golang 通道
View gochannel.go
package gochannel
import (
"fmt"
"math/rand"
"sync"
"time"
)
// 创建 wg
@tangx
tangx / uint16-posts.go
Created Nov 13, 2019
使用int位数判断特定类型的数据,例如端口
View uint16-posts.go
// "28080:80"
ports := strings.Split(s, ":")
p, err := strconv.ParseUint(ports[0], 10, 16)
if err != nil {
return nil, fmt.Errorf("invalid port %v", ports[0])
}
port = uint16(p)
@tangx
tangx / init.go
Last active Nov 12, 2019
init 初始化
View init.go
// 全局变量
var db *sql.DB
func init() {
NewConn(dsn)
}
// NewConn return a DB conn
func NewConn(dsn string) (err error) {
// sql.Open 不会
@tangx
tangx / time-usage.go
Created Nov 11, 2019
time 的常用用法
View time-usage.go
func Test_time(t *testing.T) {
start := time.Now()
time.Sleep(1 * time.Second)
sec := time.Since(start).Seconds()
fmt.Println(sec)
}
@tangx
tangx / http-client-do.go
Created Nov 11, 2019
发起自定义 http 请求
View http-client-do.go
func reqPost(url string, body io.Reader) ([]byte, error) {
req, err := http.NewRequest("POST", url, body)
if err != nil {
return nil, err
}
req.Header.Set("User-Agent", "go-dnspod (shallwedance@126.com)")
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp, err := http.DefaultClient.Do(req)
You can’t perform that action at this time.