View envvar.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package envvar | |
import ( | |
"encoding/json" | |
"fmt" | |
"os" | |
"reflect" | |
"strconv" | |
"strings" | |
) |
View lego-letsencrypt.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# lego-letsencrypt.sh | |
# | |
cd $(dirname $0) | |
which lego || { | |
lego_ver=v3.7.0 | |
wget -c https://github.com/go-acme/lego/releases/download/${lego_ver}/lego_${lego_ver}_linux_amd64.tar.gz -o lego.tar.gz |
View gochannel.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package gochannel | |
import ( | |
"fmt" | |
"math/rand" | |
"sync" | |
"time" | |
) | |
// 创建 wg |
View uint16-posts.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// "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) |
View init.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 全局变量 | |
var db *sql.DB | |
func init() { | |
NewConn(dsn) | |
} | |
// NewConn return a DB conn | |
func NewConn(dsn string) (err error) { | |
// sql.Open 不会 |
View time-usage.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func Test_time(t *testing.T) { | |
start := time.Now() | |
time.Sleep(1 * time.Second) | |
sec := time.Since(start).Seconds() | |
fmt.Println(sec) | |
} |
View http-client-do.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |