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
相关推荐
介绍通过GO语言进行网页编程方法GitHub上的源代码及MD文件压缩文件。阅读MD文件你可能需要MD阅读器cutemarked V0.11.2 http://download.csdn.net/detail/sdhongjun/9454039
谢大大编写了build-web-application-with-golang ,托管在github上,只有md版的,我个人把它编译成了chm版,共享给大家,又名《Go语言Web编程》,希望各位喜欢
介绍如何用Go语言进行Web应用的开发,将Go语言的特性与Web开发实战组合到一起,帮读者成功地构建跨平台的应用程序
Welcome to Building Web Apps with Go! If you are reading this then you have just started your journey from noob to pro. No seriously, web programming in Go is so fun and easy that you won't even ...
《构建Web应用 with Go语言》是一本开源书籍,其源代码存放在GitHub上,并被整理成"build-web-application-with-golang-master.zip"的压缩包文件。这个压缩包包含了一个完整的Go语言开发Web应用的教程项目,是学习Go...
《Learn Data Structures and Algorithms with Golang》是一本专注于使用Golang语言学习数据结构和算法的电子书,旨在帮助读者深入理解这两个编程领域的核心概念。Golang,也被称为Go语言,是由Google开发的一种静态...
1. 客户端(浏览器)发送请求到Golang服务器,请求RTSP流。 2. Golang服务器接收到请求后,连接到RTSP源,开始拉取流。 3. 服务器对RTSP流进行实时转码,转换成HLS格式。 4. 转码后的HLS片段存储在服务器的某个目录...
golang rtsp 转码到web 无插件播放
Cloud Native programming with Golang: Develop microservice-based high performance web apps for the cloud with Go Discover practical techniques to build cloud-native apps that are scalable, reliable, ...
ftp+web用户管理界面 安装博客地址:https://blog.csdn.net/zhanremo3062/article/details/123083547?spm=1001.2014.3001.5502 创作不易,感谢大家以来的支持!
Golang的web开发入门书籍,写的挺好的,排版佳。可读性强
golang搭建的http服务,用于直接显示svg条形码。 使用: go run example/main.go http://127.0.0.1:1323/C128/ABC123/2/80
aurora 是用 Go(Golang) 编写的 Web 框架 ,将是 Golang 自诞生以来最好用的 Web 开发生产工具
Go-Macross是基于Golang构建的高性能、模块化Web框架,专为提高开发效率而设计。在Golang的世界里,Web开发框架的选择至关重要,它们能够帮助开发者快速构建健壮且可扩展的Web应用程序。Macross框架就是这样一个工具...
【Golang】leetcode-golang,LeetCode solutions with Golang(Golang 实现) (Leetcode golang, LeetCode solutions with Golang (Golang implementation)) 【Golang】leetcode-golang,LeetCode solutions with Golang...
在golang中如何使用“ Web3”的示例。 更新 查阅我的小书《进行作为更好的指南。 概要 显示如何 编写智能合约 从ABI生成golang包 连接到rpc或websocket提供程序 从地址加载合同 加载私钥 调用合约方法 订阅合同事件 ...
websocket-golang-chat, 使用golang和 web sockets进行简单聊天 这是一个使用golang和 web sockets的简单网络聊天应用程序的演示。这需要去 web socket包,以获取包go get code.google.com/p/go.net/websocket获取...