This file contains hidden or 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" | |
) |
This file contains hidden or 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 |
This file contains hidden or 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 |
This file contains hidden or 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) |
This file contains hidden or 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 不会 |
This file contains hidden or 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) | |
} |
This file contains hidden or 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 ([email protected])") | |
req.Header.Set("Content-Type", "application/x-www-form-urlencoded") | |
resp, err := http.DefaultClient.Do(req) |