Golang(1)Installation and Web Application with Golang
1. Installation
Download the file from here https://go.googlecode.com/files/go1.2.darwin-amd64-osx10.8.tar.gz
Edit the path configuration
>sudo vi ~/.profile
export GOROOT=/opt/go
export PATH=/opt/go/bin:$PATH
>. ~/.profile
Verify the installation
>go version
go version go1.2 darwin/amd64
>vi hello.go
package main
import "fmt"
func main() {
fmt.Printf("hello, first installation\n")
}
>go run hello.go
hello, first installation
And few days later, I update the version to 1.2.1.
How to check my System
>uname -m
x86_64
2. Reading Book - Environment
The project is in easygo.
First of all, I create a main class that will be the executable entry for my application.
src/com/sillycat/easygoapp/main.go
package main
import (
"fmt"
)
func main() {
fmt.Printf("Hello, sillycat. \n")
}
The I use the command to build the source codes
>go build com/sillycat/easygoapp
This step will generate the binary file in the root directory named easygoapp.
>go install com/sillycat/easygoapp
This will install the binary file into directory
bin/easygoapp
Run the command
>bin/easygoapp
Hello, sillycat.
And we can also create a function class here
/src/com/sillycat/easygoapp/math/sqrt.go
package math
func Sqrt(x float64) float64 {
z := 0.0
for i := 0; i < 1000; i++ {
z -= (z*z - x) / (2 * x)
}
return z
}
Install the function
>go install com/sillycat/easygoapp/math
It will generate the .a file
/Users/carl/work/easy/easygo/pkg/darwin_amd64/com/sillycat/easygoapp/math.a
And the main file will be changed as follow:
package main
import (
"fmt"
"math"
)
func main() {
fmt.Printf("Hello, sillycat. \n")
fmt.Printf("Math result = %v\n", math.Sqrt(10))
}
3. Go Command
go build
Compile and Test, but for example, the normal package math, if you run the command go build, no file will generate.
Only >go install will generate the .a file.
If it is a main package, it will generate a executable file. Or we can say
>go build -o file path/filename
Default will compile all the .go files under the current directory.
go clean
go fmt
go get
go test
run all the files named like this *_test.go
go list
list all the package under current directory.
go run
>go run src/com/sillycat/easygoapp/main.go
4. Prepare the IDE
4.1 LiteIDE
https://github.com/visualfc/liteide
I have the go environment, and I download the binary file for MAC
Install gocode
>go get -u github.com/nsf/gocode
Find LiteEnv in the References and set the file darwin64.env
GOROOT=/opt/go
Try to start debug, but I get this Error Message
22:56:53 GdbDebugger: /usr/local/bin/gdb was not found on system PATH (hint: is GDB installed?)
22:56:53 LiteDebug: Failed to start debugger
Solution:
Install GDB
Check my env
>gdb --version
-bash: gdb: command not found
Find the software tool there
http://www.gnu.org/software/gdb/download/
http://ftp.gnu.org/gnu/gdb/
>wget http://ftp.gnu.org/gnu/gdb/gdb-7.7.tar.gz
>tar zxvf gdb-7.7.tar.gz
>./configure --prefix=/Users/carl/tool/gdb-7.7
>make
>sudo make install
>bin/gdb --version
GNU gdb (GDB) 7.7
Soft link the gdb
>sudo ln -s /Users/carl/tool/gdb-7.7 /opt/gdb-7.7
>sudo ln -s /opt/gdb-7.7 /opt/gdb
Find .profile and add
export PATH=/opt/gdb/bin:$PATH
Still do not know how to debug in LiteIDE
4.2 Sublime
sublime + gosublime + gocode + margo
I already have sublime 3. There should be some difference, but most of them should be the same.
Install Package Control
View > Show Console, or use command ‘ctrl’ + `.
Here is the command for sublime text 3.
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)
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.
‘Command’ + ’Shift’ + P, or ’Tools’ —> ‘Command Palette’
Type ‘Install Package’ and confirm.
Install ’GoSublime’
Install ’SidebarEnhancements’
Install gocode
>go get -u github.com/nsf/gocode
So it looks great right now.
4.3 Vim
…snip…
4.4 Emacs
…snip...
4.5 Eclipse
…snip…
4.6 IntelliJ IDEA
Find Plugins and install ‘Golang’
Error Message:
Problem with env variables
GOPATH environment variable is empty or could not be detected properly.
This means that some tools like go run or go fmt might not run properly.
See instructions on how to fix this. (show balloon)
Solution:
https://github.com/go-lang-plugin-org/go-lang-idea-plugin/blob/master/Missing%20ENV.md
>sudo vi /etc/launchd.conf
#limit maxfiles 16384 32768 setenv GOROOT /opt/go setenv GOPATH /Users/carl/work/easy/easygo:/Users/carl/work/go
Hope it works.
References:
http://golang.org/doc/install
Books
http://tour.golang.org/#1
https://github.com/astaxie/build-web-application-with-golang
https://github.com/go-lang-plugin-org/go-lang-idea-plugin/blob/master/Missing%20ENV.md
Install GDB
http://www.goinggo.net/2013/06/installing-go-gocode-gdb-and-liteide.html
sublime
http://lucifr.com/2011/08/31/sublime-text-2-tricks-and-tips/
https://sublime.wbond.net/installation#ST3
相关推荐
Chapter 2—Installation and Runtime Environment............................................................11 2.1 Platforms and architectures.............................................................
编程语言:golang Installation go get github.com/wuxiaoxiaoshen/jianshu-go 主要的接口包括: User: 个人主页信息 Article : 某篇文章的信息 Home-page: 简书主页的信息 Home-page-recommend: 简书推荐作者的信息...
Chapter 2—Installation and Runtime Environment............................................................11 2.1 Platforms and architectures.............................................................
晋城市-晋城市-街道行政区划_140500_Shp数据-wgs84坐标系.rar
内容概要:本文档汇总了46个经典的Linux面试题及其答案,涵盖了Linux系统操作的基本命令和概念。内容涉及路径表示与目录切换、进程管理、文件和目录操作、权限设置、文件内容查看等多个方面。每个问题都给出了明确的答案,旨在帮助面试者全面掌握Linux命令行操作技能,同时加深对Linux系统原理的理解。 适合人群:准备Linux相关职位面试的求职者,尤其是有一定Linux基础但缺乏实战经验的技术人员。 使用场景及目标:①用于个人自学或面试前复习,巩固Linux基础知识;②作为企业内部培训资料,帮助员工提升Linux操作水平;③为初学者提供系统化的学习指南,快速入门Linux命令行操作。 其他说明:文档内容侧重于实际操作命令的讲解,对于每个命令不仅提供了基本语法,还解释了具体应用场景,有助于读者更好地理解和记忆。建议读者在学习过程中多加练习,将理论知识转化为实际操作能力。
街道级行政区划shp数据,wgs84坐标系,直接下载使用。
内容概要:本文提供了10道华中杯C++竞赛真题的详细解析,涵盖多种基础编程技能与高级特性。每道题目不仅包含详细的解题思路和代码实现,还附带了完整的运行结果。具体包括:函数参数传递(指针实现)、宏定义比较、数组元素打印、几何图形面积计算、字符串拼接、素数判断、多态的实现、文件操作、简单计算器和学生信息管理。这些题目帮助读者深入理解C++语言的核心概念和技术应用。 适合人群:对C++有一定了解的编程初学者和中级开发者,尤其是准备参加编程竞赛的学生或程序员。 使用场景及目标:①作为编程练习和竞赛备考资料,帮助读者掌握C++的基本语法和常用算法;②通过实际代码示例加深对C++特性的理解,如指针、宏定义、面向对象编程等;③提供完整的源码供读者参考和调试,增强动手能力和问题解决能力。 阅读建议:建议读者按照题目难度逐步学习,先理解题目背景和解题思路,再仔细研读代码实现,并尝试独立编写和调试代码。同时,鼓励读者扩展思考,探索更多可能的解决方案,以提高编程水平。
街道级行政区划shp数据,wgs84坐标系,直接使用。
街道级行政区划shp数据,wgs84坐标系,直接使用。
通用计算器的设计FPGA.doc
晋城市-沁水县-街道行政区划_140521_Shp数据-wgs84坐标系.rar
赤峰市-松山区-街道行政区划_150404_Shp数据-wgs84坐标系.rar
JAVA中Stream编程常见的方法分类
街道级行政区划shp数据,wgs84坐标系,直接使用。
大同市-浑源县-街道行政区划_140225_Shp数据-wgs84坐标系.rar
包头市-昆都仑区-街道行政区划_150203_Shp数据-wgs84坐标系.rar
街道级行政区划shp矢量数据,wgs84坐标系,下载直接使用
街道级行政区划shp数据,wgs84坐标系,直接下载使用。
内容概要:本文详细介绍了车载电子电器架构中的网络拓扑开发,涵盖开发概述、车载网络总线、网络设计原则、开发流程及小结。网络拓扑开发是汽车电气架构中的重要环节,旨在设计合理的网络结构以确保各电子控制单元(ECU)之间的高效通信。文中阐述了通信协议选择、网络节点布局、通信介质选择、拓扑结构设计及安全性考虑等关键要素,并强调了仿真与验证的重要性。此外,还讨论了网络设计的原则,如前瞻性、兼容性、拓展性、实时性、可靠性和安全性,以及网络负载的优化措施。最后,总结了网络拓扑开发的流程,包括需求分析、设计、仿真验证、优化迭代及文档记录。 适合人群:汽车电子工程师、各域功能工程师、子系统及零部件开发者、测试工程师等从事汽车电气架构开发的相关人员。 使用场景及目标:①帮助工程师理解汽车网络拓扑开发的关键步骤和技术要点;②指导工程师在设计过程中遵循科学合理的设计原则,确保网络拓扑的高性能和可靠性;③提供网络负载优化的措施,确保数据传输的实时性和效率。 其他说明:网络拓扑开发不仅需要考虑技术层面的因素,还需兼顾成本效益,以适应不断变化的市场需求和技术趋势。本文建议读者在实践中不断积累经验,关注新技术的应用和发展,以应对未来的挑战和机遇。