go 学习笔记

Go语言命令行工具介绍-3

2018-09-26  本文已影响35人  markfork

章节

1.go build

用于编译源码文件、代码包、依赖包;

1.1 编写源代码 test.go

package main

import (
    "fmt"
    "time"
)

func main() {
    fmt.Println("test go")
    time.Sleep(3 * time.Second)
    fmt.Print("test go after 3 seconds")
}

1.2 运行 go build

go build test.go

将 test.go 源代码编译完成之后,src目录下会新增编译完成之后的 test 可运行文件,如下图所示:

编译源代码生成可运行文件

1.3 运行可直接运行的文件

./test

1.4 程序运行结果

test go
test go after 3 seconds

1.5 执行流程图示

go build & 程序运行流程

2. go run

可以编译并运行Go源码文件,包含了源文件编译、运行两个过程;

2.1 运行 go run

go run test.go

2.2 程序运行结果

test go
test go after 3 seconds

2.3 执行流程图示

go run & 程序运行流程

3. go get

主要用来动态获取远程代码包;没啥可记录的,类似wget;

注意:go语言命令行工具 与 go语言本身是有区别的

上一篇下一篇

猜你喜欢

热点阅读