2018 Golang Update(1)Version 1.10 and Gin

本文详细记录了从旧版本Go升级到Go 1.10的过程,并介绍了如何在Mac上安装配置Go环境。此外,还通过实例展示了如何使用Go语言编写简单的应用程序和服务,包括基本的数学运算函数实现及Web框架Gin的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

2018 Golang Update(1)Version 1.10 and Gin

My Old version of golang is
>go version
go version go1.5.3 darwin/amd64

Try to check the latest version and install on my Mac Pro
>go version
go version go1.10 darwin/amd64

Verify the installation
>cat src/hello/hello.go
package main

import "fmt"

func main() {
fmt.Printf("hello, world\n")
}

go to the directory
>cd src/hello/
Build the src
>go build

Run the application
>./hello
hello, world

Manually install the binary
>wget https://dl.google.com/go/go1.10.darwin-amd64.tar.gz
>tar zxvf go1.10.darwin-amd64.tar.gz
Move to working directory
>mv go /Users/carl/tool/go-1.10

>sudo ln -s /Users/carl/tool/go-1.10 /opt/go-1.10
>sudo ln -s /opt/go-1.10 /opt/go

Add to Path
export GOROOT="/opt/go"
export GOPATH="/Users/carl/work/easy/easygo"
PATH="/opt/go/bin:$PATH"

Example
cat src/com/sillycat/easygoapp/main.go
package main

import "fmt"

func main(){
fmt.Printf("hello, sillycat\n")
}

Generate the binary
>go install com/sillycat/easygoapp

Run the binary
>bin/easygoapp
hello, sillycat

Build a function
>cat 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 that
>go install com/sillycat/easygoapp/math

Update the main method
>cat src/com/sillycat/easygoapp/main.go
package main

import "fmt"
import "math"

func main(){
fmt.Printf("hello, sillycat\n")
fmt.Printf("math result = %v\n", math.Sqrt(10))
}

Build and run that
>go install com/sillycat/easygoapp
>bin/easygoapp
hello, sillycat
math result = 3.1622776601683795

Try this IDE
https://github.com/visualfc/liteide/releases/tag/x33.2
sublime text 3 ’Tools’ —> ‘Command Palette’
Install ‘GoSublime’
Install ’SidebarEnhancements'

Some Grammar
http://sillycat.iteye.com/blog/2047158
public property, public Function, Capital first character
private property,private Function, Lower case first character

Try with a WebFramework to build a Service
https://github.com/gin-gonic/gin
http://himarsh.org/build-restful-api-microservice-with-go/

References:
https://golang.org/

Previous Notes
http://sillycat.iteye.com/admin/blogs/2037798 env
http://sillycat.iteye.com/blog/2047158 grammar
http://sillycat.iteye.com/blog/2052936 grammar
http://sillycat.iteye.com/blog/2052937 grammar
http://sillycat.iteye.com/blog/2056435 grammar
http://sillycat.iteye.com/blog/2056443 web HTTP request handler
http://sillycat.iteye.com/blog/2057320 database layer
http://sillycat.iteye.com/blog/2065123 NoSQL Redis/MongoDB
http://sillycat.iteye.com/blog/2065585 File XML, JSON
http://sillycat.iteye.com/blog/2068488 Web Socket
http://sillycat.iteye.com/blog/2068862 RESTful MUX
http://sillycat.iteye.com/blog/2069405 JSON Mapping
http://sillycat.iteye.com/blog/2069453 security base64, AES DES,
http://sillycat.iteye.com/blog/2070140 Logging and Error Handler
http://sillycat.iteye.com/blog/2070161 deployment
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值