![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
go
不正经运维君
这个作者很懒,什么都没留下…
展开
-
go接收post来的json数据
cat postHttpServer.gopackage mainimport ( "fmt" "io/ioutil" "log" "net/http")func mockWebhook(w http.ResponseWriter, r *http.Request) { if r.URL.Path != "/webhook" { http.Error(w, "404 not found.", http.StatusNotFound) return } switch r.原创 2021-12-17 10:05:02 · 2174 阅读 · 0 评论 -
go字符串处理
正则网站在线正则调试以指定字符开头的行package mainimport ( "fmt" "strings")func main(){ var stra string = "#号开头" if strings.HasPrefix(stra,"#") { fmt.Println(stra) } var strb string = " 非#开头 #号前面有空格" if !strings.HasPrefix(strb,"#") { fmt.Println(strb) }原创 2021-10-20 15:19:21 · 100 阅读 · 0 评论 -
go 按行替换文本中字符串
package mainimport ( "bufio" "fmt" "io" "os" "strings")func main() { fileName := "test.file" in, err := os.Open(fileName) if err != nil { fmt.Println("open file fail:", err) os.Exit(-1) } defer in.Close() out, err := os.OpenFile(fileNa原创 2021-05-24 12:56:43 · 424 阅读 · 0 评论 -
go 交叉编译
win2linuxGOOS=linux GOARCH=amd64 go build hello.go原创 2021-05-24 13:13:54 · 208 阅读 · 0 评论 -
Go语言http
package mainimport ( "io" "log" "net/http")func main() { http.HandleFunc("/hello", func(w http.ResponseWriter, req *http.Request) { io.WriteString(w, "hello, world!\n")}) err := http.ListenAndServe(":9091", nil) if err != nil { log.Fatal("L原创 2021-06-08 12:19:53 · 53 阅读 · 0 评论 -
Go语言发送邮件
package mainimport ( "gopkg.in/gomail.v2")func main() {sendMail()}func sendMail() { m := gomail.NewMessage() m.SetHeader("From", "发送者的邮箱") m.SetHeader("To", "收件箱1", "收件箱2") //m.SetAddressHeader("Cc", "抄送给邮箱", "tony") m.SetHeader("Subject",原创 2021-06-07 22:09:43 · 536 阅读 · 0 评论 -
Go 生成随机数
package mainimport ( "fmt" "math/rand" "strconv" "time")func main() { fmt.Println(randomNumber())}func randomNumber() string { rand.Seed(time.Now().UnixNano()) code := rand.Intn(666666) + 100000 str := strconv.Itoa(code) return str}原创 2021-06-07 21:28:26 · 108 阅读 · 0 评论 -
Go语言urfave/cl库学习
v1package mainimport ( "fmt" "github.com/urfave/cli" "os")func main() { app := cli.App{ Action: func(c *cli.Context) { fmt.Println("hello world") }, } app.Run(os.Args)}Action 是一个 interface{}原创 2021-06-07 11:22:59 · 444 阅读 · 0 评论 -
go语言保存docker镜像(支持windows mac linux)-(不使用tls连接docker引擎版本)
go.modmodule yunweigo 1.16require ( github.com/Microsoft/go-winio v0.4.18 // indirect github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6 // indirect github.com/aws/aws-sdk-go v1.38.24 // indirect github.com/containerd/containerd v1.4.4原创 2021-05-31 18:01:04 · 389 阅读 · 1 评论 -
go读取json文件
books.json{ "books": [{ "Name": "看不见的城市", "author": ["卡尔维诺"] }, { "Name": "红楼梦", "author": ["曹雪芹", "高鹗"] } ]}read_json_from_file.gopackage mainimport ( "encoding/json" "fmt" "os")type Book struct { Name str原创 2021-05-31 12:46:32 · 422 阅读 · 0 评论 -
connect_dockerd_without_tls
package mainimport ( "context" "fmt" "github.com/docker/docker/api/types" "github.com/docker/docker/client")func main() { // ctx := context.Background() cli, err := client.NewClientWithOpts(client.WithHost("tcp://192.168.160.101:2375"),client.W原创 2021-05-26 16:52:27 · 138 阅读 · 0 评论 -
go 获取指定网卡的ip
package mainimport ( "errors" "fmt" "net")func main() { ip, err := GetInterfaceIpv4Addr("eth0") if err != nil { fmt.Println(err) } fmt.Println(ip)}func GetInterfaceIpv4Addr(interfaceName string) (addr string, err error) { var ( ief原创 2021-05-24 09:55:17 · 2380 阅读 · 0 评论 -
viper 库读取toml 配置文件
package mainimport ( "fmt" "log" "github.com/spf13/viper")func main() { viper.SetConfigName("config.toml") //配置文件名字 viper.SetConfigType("toml") //配置文件类型 viper.AddConfigPath(".") //配置文件搜索路径 err := viper.ReadInConfig() if err !原创 2021-04-19 13:58:48 · 1028 阅读 · 0 评论