... in golang!") } func main() { http.HandleFunc("/", handler) http.ListenAndServeTLS(":9090", "server.crt","server.key", nil) } 访问: go ...
... .Println(db) } 使用示例: https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/05.2.md
... main() { buf := `{ "company":"itcast", "subjects": [ "go", "c++", "python" ], "Isok": true, " ...
开发环境搭建: 下载开发环境包:https://www.golangtc.com/download 下载后安装即可,安装好后打开cmd 运行 go version 如果现实版本号说明已近安装成功。 开发工具下载: https://sourceforge.net/projects/liteide/files/ 这个开发工具下载后解压就可以使用了。
... ;time" ) func main() { ch := make(chan int) quit := make(chan bool) go func() { for { select { case num := <-ch: fmt.Println("num = " ...
... 阻塞 Printer("world") } func main() { // 这样会出现资源竞争 go Person1() go Person2() for { } } channel: package main import ( "fmt" "time ...
... () if err != nil { fmt.Println("err = ", err) return } go HandleConn(conn) } } tcp_client.go package main import ( "fmt" "net" "os ...
... .Index("ssscccaaaccc", "vvv")) // Repeat buf = strings.Repeat("golang", 3) fmt.Println(buf) // Split 分割字符串 buf = "aaa@bbb ...
运行go文件: go run demo.go 在编译源代码之后还安装到指定的目录 go install ... 生成可执行文件 go build demo.go 从指定源上面下载或者更新指定的代码和依赖,并对他们进行编译和安装 go get = git clone + go install
... .NewTimer(3 * time.Second) // 3s后往timer通道中写时间 go func() { num := <-timer.C // 未读出内容时一直保持死锁 ...
... ("test() hello", i) time.Sleep(time.Millisecond * 100) } } func main() { go test() fmt.Println(" ") for i := 0; i < 20; i ...
在git bash里设置代理: export https_proxy=http://192.168.0.10:8118 export http_proxy=http://192.168.0.10:8118 git config --global http.proxy 'http://192.168.0.10:8118' git ...
package main import ( "fmt" "os" ) func main() { // 标准输出设备 // os.Stdout.Close() //fmt.Println("123") // os.Stdout.WriteString("hello") // ...
匿名成员的使用: package main import "fmt" type Person struct{ name string sex byte age int } type Student struct{ Person id int addr string } func main() { // 匿名字段初始化 var s1 ...
结构体定义与赋值: package main import "fmt" type Student struct { id int name string sex byte age int addr string } func main() { // 初始化并赋值,且每个元素都要赋值 var s1 Student = Student{1 ...
面相对象: package main import "fmt" type long int // 方法,面向对象编程 func (tmp long) Add(other long) long{ return tmp + other } func main(){ var a long = 2 b := a.Add(3) fmt. ...
接口的定义和实现: package main import "fmt" type Humaner interface { sayhi() } type Student struct { id int name string } type Teacher struct { addr string group string } func ...
正则的使用: package main import ( "fmt" "regexp" ) func main() { buf := "abc axc adc qwe fff aaa" // 解析正则 reg := regexp.MustCompile(`a.c`) if reg == nil ...
error接口的使用: package main import ( "errors" "fmt" ) func main() { var err1 error = fmt.Errorf("%s", "This is error1") err2 := fmt.Errorf(& ...
写入内容到文件: package main import ( "fmt" "os" ) func WriteFile(path string) { f, err := os.Create(path) if err != nil { fmt.Println("err = ", err) ...