Golang(1)Installation and Web Application with Golang

前端之家收集整理的这篇文章主要介绍了Golang(1)Installation and Web Application with Golang前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Golang(1)Installation and Web Application with Golang@H_404_4@@H_404_4@1. Installation@H_404_4@Download the file from herehttps://go.googlecode.com/files/go1.2.darwin-amd64-osx10.8.tar.gz@H_404_4@@H_404_4@Edit the path configuration@H_404_4@>sudo vi ~/.profile@H_404_4@export GOROOT=/opt/go@H_404_4@export PATH=/opt/go/bin:$PATH@H_404_4@>. ~/.profile@H_404_4@@H_404_4@Verify the installation@H_404_4@>go version@H_404_4@go version go1.2 darwin/amd64@H_404_4@@H_404_4@>vi hello.go@H_404_4@package main import "fmt" func main() { fmt.Printf("hello,first installation\n")@H_404_4@}@H_404_4@@H_404_4@>go run hello.go@H_404_4@hello,first installation@H_404_4@@H_404_4@And few days later,I update the version to 1.2.1.@H_404_4@@H_404_4@How to check my System@H_404_4@>uname -m@H_404_4@x86_64@H_404_4@@H_404_4@2. Reading Book - Environment@H_404_4@The project is in easygo.@H_404_4@@H_404_4@First of all,I create a main class that will be the executable entry for my application.@H_404_4@src/com/sillycat/easygoapp/main.go@H_404_4@package main@H_404_4@@H_404_4@import (@H_404_4@ "fmt"@H_404_4@)@H_404_4@@H_404_4@func main() {@H_404_4@ fmt.Printf("Hello,sillycat. \n")@H_404_4@}@H_404_4@@H_404_4@The I use the command to build the source codes@H_404_4@>go build com/sillycat/easygoapp@H_404_4@@H_404_4@This step will generate the binary file in the root directory named easygoapp.@H_404_4@>go install com/sillycat/easygoapp@H_404_4@@H_404_4@This will install the binary file into directory@H_404_4@bin/easygoapp@H_404_4@@H_404_4@Run the command@H_404_4@>bin/easygoapp@H_404_4@Hello,sillycat.@H_404_4@@H_404_4@And we can also create a function class here@H_404_4@/src/com/sillycat/easygoapp/math/sqrt.go@H_404_4@package math@H_404_4@@H_404_4@func Sqrt(x float64) float64 {@H_404_4@ z := 0.0@H_404_4@ for i := 0; i < 1000; i++ {@H_404_4@ z -= (z*z - x) / (2 * x)@H_404_4@ }@H_404_4@ return z@H_404_4@}@H_404_4@@H_404_4@Install the function@H_404_4@>go install com/sillycat/easygoapp/math@H_404_4@@H_404_4@It will generate the .a file@H_404_4@/Users/carl/work/easy/easygo/pkg/darwin_amd64/com/sillycat/easygoapp/math.a@H_404_4@@H_404_4@And the main file will be changed as follow:@H_404_4@package main@H_404_4@@H_404_4@import (@H_404_4@ "fmt"@H_404_4@ "math"@H_404_4@)@H_404_4@@H_404_4@func main() {@H_404_4@ fmt.Printf("Hello,sillycat. \n")@H_404_4@ fmt.Printf("Math result = %v\n",math.Sqrt(10))@H_404_4@}@H_404_4@@H_404_4@3. Go Command@H_404_4@go build@H_404_4@Compile and Test,but for example,the normal package math,if you run the command go build,no file will generate.@H_404_4@Only >go install will generate the .a file.@H_404_4@@H_404_4@If it is a main package,it will generate a executable file. Or we can say@H_404_4@>go build -o file path/filename@H_404_4@@H_404_4@Default will compile all the .go files under the current directory.@H_404_4@@H_404_4@go clean@H_404_4@@H_404_4@go fmt@H_404_4@@H_404_4@go get@H_404_4@@H_404_4@go test@H_404_4@run all the files named like this *_test.go@H_404_4@@H_404_4@go list@H_404_4@list all the package under current directory.@H_404_4@@H_404_4@go run@H_404_4@>go run src/com/sillycat/easygoapp/main.go@H_404_4@@H_404_4@4. Prepare the IDE@H_404_4@4.1 LiteIDE@H_404_4@https://github.com/visualfc/liteide@H_404_4@I have the go environment,and I download the binary file for MAC@H_404_4@@H_404_4@Install gocode@H_404_4@>go get -u github.com/nsf/gocode@H_404_4@@H_404_4@Find LiteEnv in the References and set the file darwin64.env@H_404_4@GOROOT=/opt/go@H_404_4@Try to start debug,but I get this Error Message@H_404_4@22:56:53 GdbDebugger: /usr/local/bin/gdb was not found on system PATH (hint: is GDB installed?)@H_404_4@22:56:53 LiteDebug: Failed to start debugger@H_404_4@Solution:@H_404_4@Install GDB@H_404_4@Check my env@H_404_4@>gdb --version@H_404_4@-bash: gdb: command not found@H_404_4@@H_404_4@Find the software tool there@H_404_4@http://www.gnu.org/software/gdb/download/@H_404_4@http://ftp.gnu.org/gnu/gdb/@H_404_4@@H_404_4@>wget http://ftp.gnu.org/gnu/gdb/gdb-7.7.tar.gz@H_404_4@>tar zxvf gdb-7.7.tar.gz@H_404_4@@H_404_4@>./configure --prefix=/Users/carl/tool/gdb-7.7@H_404_4@>make@H_404_4@>sudo make install@H_404_4@@H_404_4@>bin/gdb --version@H_404_4@GNU gdb (GDB) 7.7@H_404_4@@H_404_4@Soft link the gdb@H_404_4@>sudo ln -s /Users/carl/tool/gdb-7.7 /opt/gdb-7.7@H_404_4@>sudo ln -s /opt/gdb-7.7 /opt/gdb@H_404_4@@H_404_4@Find .profile and add@H_404_4@export PATH=/opt/gdb/bin:$PATH@H_404_4@@H_404_4@Still do not know how to debug in LiteIDE@H_404_4@@H_404_4@4.2 Sublime@H_404_4@sublime + gosublime + gocode + margo@H_404_4@@H_404_4@I already have sublime 3. There should be some difference,but most of them should be the same.@H_404_4@@H_404_4@Install Package Control@H_404_4@View > Show Console,or use command ‘ctrl’ + `.@H_404_4@@H_404_4@Here is the command for sublime text 3.@H_404_4@import urllib.request,os,hashlib; h = '7183a2d3e96f11eeadd761d777e62404' + 'e330c659d4bb41d3bdf022e94cab3cd0'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( 'http://sublime.wbond.net/' + pf.replace(' ','%20')).read(); dh = hashlib.sha256(by).hexdigest(); print('Error validating download (got %s instead of %s),please try manual install' % (dh,h)) if dh != h else open(os.path.join( ipp,pf),'wb' ).write(by)@H_404_4@@H_404_4@After that,I restart my sublime,and I saw the menu ‘References’ ——> ‘Package Control’,Great,then we can install the plugins we need for sublime 3.@H_404_4@@H_404_4@‘Command’ + ’Shift’ + P,or ’Tools’ —> ‘Command Palette’@H_404_4@@H_404_4@Type ‘Install Package’ and confirm.@H_404_4@@H_404_4@Install ’GoSublime’@H_404_4@Install ’SidebarEnhancements’@H_404_4@@H_404_4@Install gocode@H_404_4@>go get -ugithub.com/nsf/gocode@H_404_4@@H_404_4@So it looks great right now.@H_404_4@@H_404_4@4.3 Vim@H_404_4@…snip…@H_404_4@@H_404_4@4.4 Emacs@H_404_4@…snip...@H_404_4@@H_404_4@4.5 Eclipse@H_404_4@…snip…@H_404_4@@H_404_4@4.6 IntelliJ IDEA@H_404_4@Find Plugins and install ‘Golang’@H_404_4@@H_404_4@Error Message:@H_404_4@Problem with env variables@H_404_4@ GOPATH environment variable is empty or could not be detected properly.@H_404_4@ This means that some tools like go run or go fmt might not run properly.@H_404_4@ See instructions on how to fix this. (show balloon)@H_404_4@@H_404_4@Solution:@H_404_4@https://github.com/go-lang-plugin-org/go-lang-idea-plugin/blob/master/Missing%20ENV.md@H_404_4@@H_404_4@>sudo vi /etc/launchd.conf@H_404_4@#limit maxfiles 16384 32768 setenv GOROOT /opt/go setenv GOPATH /Users/carl/work/easy/easygo:/Users/carl/work/go@H_404_4@@H_404_4@Hope it works.@H_404_4@@H_404_4@References:@H_404_4@http://golang.org/doc/install@H_404_4@@H_404_4@Books@H_404_4@http://tour.golang.org/#1@H_404_4@https://github.com/astaxie/build-web-application-with-golang@H_404_4@@H_404_4@https://github.com/go-lang-plugin-org/go-lang-idea-plugin/blob/master/Missing%20ENV.md@H_404_4@@H_404_4@Install GDB@H_404_4@http://www.goinggo.net/2013/06/installing-go-gocode-gdb-and-liteide.html@H_404_4@@H_404_4@sublime@H_404_4@http://lucifr.com/2011/08/31/sublime-text-2-tricks-and-tips/@H_404_4@https://sublime.wbond.net/installation#ST3

原文链接:https://www.f2er.com/go/191038.html

猜你在找的Go相关文章