當前的調試部分可以使用 go run filename.go 來執(zhí)行。
可以生成一個 build.sh 腳本,用于在指定位置產生已編譯好的 可執(zhí)文件:
#!/usr/bin/env bash CURRENT_DIR=`pwd` OLD_GO_PATH="$GOPATH" #例如: /usr/local/go OLD_GO_BIN="$GOBIN" #例如: /usr/local/go/bin export GOPATH="$CURRENT_DIR" export GOBIN="$CURRENT_DIR/bin" #指定并整理當前的源碼路徑 gofmt -w src go install test_hello export GOPATH="$OLD_GO_PATH" export GOBIN="$OLD_GO_BIN"
關于包,根據(jù)本地測試得出以下幾點:
文件結構:
Test --helloworld.go myMath --myMath1.go --myMath2.go
測試代碼:
// helloworld.go package main import ( "fmt" "./myMath" ) func main(){ fmt.Println("Hello World!") fmt.Println(mathClass.Add(1,1)) fmt.Println(mathClass.Sub(1,1)) } // myMath1.go package mathClass func Add(x,y int) int { return x + y } // myMath2.go package mathClass func Sub(x,y int) int { return x - y }
到此這篇關于Go 語言結構實例分析的文章就介紹到這了,更多相關Go 語言結構內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
上一篇:Go語言基礎知識點介紹
下一篇:Go語言空白表示符_的實例用法