短域名应用很火啊,搜了一下实现方式也五花八门,语言上php,java,python任您选择,环境包括tomcat,nginx+lua,nodejs等等。因项目需要,公司也要出一款短域名的应用,公司PM做出了一个艰难的决定,准备用go,go是神马玩意儿啊?大叔您从哪听到的这玩意性能好啊~
也是,这年头什么都要追求潮流,啥都要整个高大上,一句话:没用过golang的程序员不是好厨子!咱也废话少叙,先把环境搭建起来再说。
整理了一下,网上关于golang的安装有三种方式,总有一款适合您~(注明一下,我的环境为CentOS-6.x, 64bit)
方式一:yum安装(最简单)
rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm yum install golang
方式二:源码安装:
wget http://go.googlecode.com/files/go1.2.linux-amd64.tar.gz tar -xvf go1.2.linux-amd64.tar.gz sudo cp -r go /usr/local/go vi /etc/profile export GOROOT=/usr/local/go export PATH=$PATH:$GOROOT/bin source /etc/profile
方式三:类似源码安装
1. $ sudo yum install mercurial 2. $ hg clone -u release https://go.googlecode.com/hg/ golang 3. To build the Go distribution, run $ cd go/src $ ./all.bash 4. If all goes well, it will finish by printing output like: ALL TESTS PASSED---Installed Go for linux/amd64 in /home/you/go.Installed commands in /home/you/go/bin.*** You need to add /home/you/go/bin to your $PATH. ***
安装完毕之后看看状态:
$go version go version go1.2 linux/amd64
测试文件
cat hello.go package main import "fmt" func main() { fmt.Printf("what's up, sudops.com\n") }
运行:
go run hello.go what's up, sudops.com
项目还是处在调研阶段,我个人认为环境应该还用到redis(key/value)和nginx(web engine),由nginx通过fastcgi的方式来调用golang的cgi页面,不过有些怀疑其性能是否比nginx+lua强呢?