2018 Golang Update(1)Version 1.10 and Gin

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


猜你喜欢

转载自sillycat.iteye.com/blog/2411121