新聞中心
如何為L(zhǎng)inux安裝Go語(yǔ)言
1、首先打開(kāi)開(kāi)始菜單運(yùn)行cmd。
站在用戶(hù)的角度思考問(wèn)題,與客戶(hù)深入溝通,找到長(zhǎng)洲網(wǎng)站設(shè)計(jì)與長(zhǎng)洲網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶(hù)體驗(yàn)好的作品,建站類(lèi)型包括:成都做網(wǎng)站、網(wǎng)站設(shè)計(jì)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名注冊(cè)、雅安服務(wù)器托管、企業(yè)郵箱。業(yè)務(wù)覆蓋長(zhǎng)洲地區(qū)。
2、然后輸入go回車(chē)。出現(xiàn)一下畫(huà)面表示已經(jīng)安裝完畢。
如果用戶(hù)沒(méi)有配置可能是安裝過(guò)程中出了點(diǎn)小錯(cuò)誤,那么可以自行配制,也可以重新安裝。
自行配置方法
1、首先打開(kāi)計(jì)算機(jī)的屬性,點(diǎn)擊高級(jí)系統(tǒng)設(shè)置。
2、然后在環(huán)境變量Path中加上變量C:\Go\bin。
3、然后再點(diǎn)擊新建,添加一個(gè)新的環(huán)境變量。
變量名:GOROOT
變量值:C:\Go\
完成后根據(jù)上面的方法驗(yàn)證。
Go語(yǔ)言
windows 怎么編譯 go語(yǔ)言
1、解壓壓縮包到go工作目錄,如解壓到E:\opensource\go\go,解壓后的目錄結(jié)構(gòu)如下:
E:\opensource\go\go
├─api
├─bin
│ ├─go.exe
│ ├─godoc.exe
│ └─gofmt.exe
├─doc
├─include
├─lib
├─misc
├─pkg
├─src
└─test
2、增加環(huán)境變量GOROOT,取值為上面的go工作目錄
3、Path環(huán)境變量中添加";%GOROOT%\bin",以便能夠直接調(diào)用go命令來(lái)編譯go代碼,至此go編譯環(huán)境就配置好了
注:如果不想手動(dòng)設(shè)置系統(tǒng)環(huán)境變量,也可下載go啟動(dòng)環(huán)境批處理附件,
修改goenv.bat文件中的GOROOT值為上面的go工作目錄后直接雙擊該bat文件,go編譯環(huán)境變量即設(shè)置完成。
4、測(cè)試go編譯環(huán)境,啟動(dòng)一個(gè)cmd窗口,直接輸入go,看到下面的提示就是搭建成功了
E:\opensource\go\gogo
Go is a tool for managing Go source code.
Usage:
go command [arguments]
The commands are:
build compile packages and dependencies
clean remove object files
doc run godoc on package sources
env print Go environment information
fix run go tool fix on packages
fmt run gofmt on package sources
get download and install packages and dependencies
install compile and install packages and dependencies
list list packages
run compile and run Go program
test test packages
tool run specified go tool
version print Go version
vet run go tool vet on packages
Use "go help [command]" for more information about a command.
Additional help topics:
gopath GOPATH environment variable
packages description of package lists
remote remote import path syntax
testflag description of testing flags
testfunc description of testing functions
Use "go help [topic]" for more information about that topic.
5、編譯helloworld測(cè)試程序,go語(yǔ)言包中test目錄帶有helloworld.go測(cè)試程序,源碼見(jiàn)"附一 helloworld.go",
直接調(diào)用"go build helloworld.go"就生成了"helloworld.exe"可執(zhí)行程序,運(yùn)行一下這個(gè)程序看到了我們期望的hello,wolrd。
E:\opensource\go\go\testgo build helloworld.go
E:\opensource\go\go\testhelloworld.exe
hello, world
E:\opensource\go\go\test
附一 helloworld.go
// cmpout
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Test that we can do page 1 of the C book.
package main
func main() {
print("hello, world\n")
}
go中使用cmd與cron
/bin/bash -c "ls -l"
cmd-golang-pipe
pipe()創(chuàng)建2個(gè)文件描述符,fd[0]可讀,fd[1]可寫(xiě)
fork() 創(chuàng)建子進(jìn)程 fd[1]被繼承到子進(jìn)程
dup2() 重定向子進(jìn)程 stdout/stderr到fd[1]
exec() 在當(dāng)前進(jìn)程內(nèi),加載并執(zhí)行二進(jìn)制程序
模擬一下cmd調(diào)用
模擬調(diào)用cmd時(shí),殺死bash進(jìn)程
go開(kāi)源Cronexpr庫(kù)
Parse() 解析與校驗(yàn)Cron表達(dá)式
Next() 根據(jù)當(dāng)前時(shí)間,計(jì)算下一次調(diào)度時(shí)間
模擬一下cron調(diào)用
執(zhí)行結(jié)果
模擬多個(gè)cron調(diào)用
執(zhí)行結(jié)果
網(wǎng)站欄目:go語(yǔ)言新窗口啟動(dòng)cmd go窗口程序
分享地址:http://fisionsoft.com.cn/article/dodgdeo.html