golang
已收录文章:13896篇
-
1. 执行命令并获得输出结果 CombinedOutput() 执行程序返回 standard output and standard error func main() { cmd := exec.Command("ls", "-lah") out, err := cmd.CombinedOutput() if err != nil { log.Fatalf("cmd.Run() failed w426 收藏
-
在我们编程过程中,经常会用到与时间相关的各种务需求,下面来介绍 golang 中有关时间的一些基本用法,我们从 time 的几种 type 来开始介绍。 时间可分为时间点与时间段,golang 也不例外,提供149 收藏
-
概览 最近阅读源码的时候看到一段不错的代码,但是当时却不是非常理解为什么这么写。 我们先来看一下源代码: type User struct { ID string Name string Age int Email string Phone string Gender s258 收藏
-
可以压缩文件和目录。 package main import ( "archive/zip" "bytes" "fmt" "io/ioutil" "os" "path/filepath" ) func main() { if err := compress(`gopkg`, `gopkg.zip`); err != nil { fmt.Println(err) } } // 参数frm可以是文件282 收藏
-
GoLang调试工具Delve 1.先获取呗: go get -u github.com/derekparker/delve/cmd/dlv 2.编写测试代码呗: func main(){ http.HandleFunc("/test",func(writer http.ResponseWriter,req *http.Request){ //TODO }) log.Fatal(http.ListenAndServe("127.286 收藏
-
Golang的string类型底层数据结构简单,本质也是一个结构体实例,且是const不可变。 string的底层数据结构 通过下面一个例子来看: package main import ( "fmt" "unsafe" ) // from: string.go 在GoLand IDE中双击s480 收藏