(Go)04.go工作区目录规范及简单例子
2024-09-08 01:53:18
一.规范目录结构
D:\project\src\go_dev\day1\example1
二.设置GOPAH环境变量
三.hello world
1.hello world
package main import (
"fmt"
) func main () {
fmt.Println("Hello World!")
}
go build go_dev\day1\example1
生成example1.exe
执行example1.exe
2.goroute循环
goroute.go
package main import (
"fmt"
) func test_goroute(a int) {
fmt.Println(a)
}
main.go
package main import (
"time"
) func main() { for i :=; i <; i++ {
go test_goroute(i)
}
time.Sleep(*time.Second)
}
3.goroute_example
代码目录结构
package goroute func Add(a int, b int, c chan int) {
sum := a + b
c <- sum }
add.go
package main import (
"go_dev/day1/goroute_example/goroute"
"fmt"
) func main() {
//var pipe chan int
//pipe = make(chan int, 1) pipe := make(chan int, ) //等同于上二行
go goroute.Add(, , pipe) sum := <- pipe
fmt.Println("sum =", sum)
}
main.go
构建代码
D:\project>go build -o bin/goroute_example.exe go_dev/day1/goroute_example/main
D:\project\bin>goroute_example.exe
sum = 400
最新文章
- linux 卸载编译安装的软件
- Linux下设置环境变量
- php页面编码与字符操作
- Power-BI 预警触发的设定
- 上传图片预览设置src不显示
- [CareerCup] 10.5 Web Crawler 网络爬虫
- oracle linux 下卸载
- cssText在 IE6/7/8和chrome/Firefox/IE9+的不同
- 用rem来做响应式开发
- 美化select的jquery插件
- 微信jsapi支付的坑
- 深入浅出AQS之共享锁模式
- RabbitMQ可靠性投递及高可用集群
- C++中int与string的相互转换【转】
- Elasticsearch基本用法(2)--Spring Data Elasticsearch
- 去7JAVA
- Centos 7 安装 Redis 3.2
- Flexbox指南
- Volley的Get、Post方式(JsonObjectRequest、StringRequest)以及Volley获取图片的3种方式
- spring boot读取配置文件