Top Banner
9/25/2016 Go Installfest http://localhost:3999/present.slide#34 1/35 Go Installfest 24 December 2016 Thach Le Triet Pham
35

Go Installfest

Jan 22, 2018

Download

Documents

Lê Thạch
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Go Installfest

9/25/2016 Go Installfest

http://localhost:3999/present.slide#34 1/35

Go Installfest24 December 2016

Thach LeTriet Pham

Page 2: Go Installfest

9/25/2016 Go Installfest

http://localhost:3999/present.slide#34 2/35

Who are we?

Programming addict

Java, NodeJS, Go

Backend at DF/Backend at Lozi

1.5 years with Go

runikitkat.com (http://runikitkat.com)

Page 3: Go Installfest

9/25/2016 Go Installfest

http://localhost:3999/present.slide#34 3/35

Goal

Help new gophers know what exactly they need to start using Go.

Page 4: Go Installfest

9/25/2016 Go Installfest

http://localhost:3999/present.slide#34 4/35

Agenda

Install, set up Go

Go commands + tools

Glide

Beego

Gin

Gorm

gRPC

Page 5: Go Installfest

9/25/2016 Go Installfest

http://localhost:3999/present.slide#34 5/35

Install, set up Go

Page 6: Go Installfest

9/25/2016 Go Installfest

http://localhost:3999/present.slide#34 6/35

Install Go

Using HomeBrew

Download from Homepage(https://golang.org/doc/install)

Install from source.

Page 7: Go Installfest

9/25/2016 Go Installfest

http://localhost:3999/present.slide#34 7/35

Set up Go

GOPATH

GOBIN

GOROOT

PATH

Page 8: Go Installfest

9/25/2016 Go Installfest

http://localhost:3999/present.slide#34 8/35

Go commands + tools

Page 9: Go Installfest

9/25/2016 Go Installfest

http://localhost:3999/present.slide#34 9/35

Commands

go build

go test

go run

go get

go fmt

go lint

go vet

Page 10: Go Installfest

9/25/2016 Go Installfest

http://localhost:3999/present.slide#34 10/35

Integrate with Editor/IDE

Vim: vim-go

Emacs: go-mode

Sublime: GoSublime

Atom: go-plus

VSCode: vscode-go

Page 11: Go Installfest

9/25/2016 Go Installfest

http://localhost:3999/present.slide#34 11/35

Hello world

package main import "fmt" func main() { fmt.Println("Hello world") }

Page 12: Go Installfest

9/25/2016 Go Installfest

http://localhost:3999/present.slide#34 12/35

Go import

package main import "github.com/k0kubun/pp" func main() { pp.Println("Hello world") }

Page 13: Go Installfest

9/25/2016 Go Installfest

http://localhost:3999/present.slide#34 13/35

Glide

Page 14: Go Installfest

9/25/2016 Go Installfest

http://localhost:3999/present.slide#34 14/35

Introduction

Cargo, npm, pip, Maven...

Packages manager

Page 15: Go Installfest

9/25/2016 Go Installfest

http://localhost:3999/present.slide#34 15/35

Install

curl https://glide.sh/get | sh

brew install glide

Page 16: Go Installfest

9/25/2016 Go Installfest

http://localhost:3999/present.slide#34 16/35

Usage

$ glide create # Start a new workspace $ open glide.yaml # and edit away! $ glide get github.com/Masterminds/cookoo # Get a package and add to glide.yaml $ glide install # Install packages and dependencies # work, work, work $ go build # Go tools work normally $ glide up # Update to newest versions of the package

Page 17: Go Installfest

9/25/2016 Go Installfest

http://localhost:3999/present.slide#34 17/35

Beego

Page 18: Go Installfest

9/25/2016 Go Installfest

http://localhost:3999/present.slide#34 18/35

Introduction

http://beego.me/

Fullstack web framework

RESTful, MVC model

High performance

Page 19: Go Installfest

9/25/2016 Go Installfest

http://localhost:3999/present.slide#34 19/35

Installation

go get github.com/astaxie/beego

go get github.com/beego/bee

Page 20: Go Installfest

9/25/2016 Go Installfest

http://localhost:3999/present.slide#34 20/35

Using

$ cd $GOPATH/src $ bee new hello $ cd hello $ bee run

Page 21: Go Installfest

9/25/2016 Go Installfest

http://localhost:3999/present.slide#34 21/35

Gin

Page 22: Go Installfest

9/25/2016 Go Installfest

http://localhost:3999/present.slide#34 22/35

Introduction

https://gin-gonic.github.io/gin/

Minimal framework - but use for API much better

Fast

Easy to use

Page 23: Go Installfest

9/25/2016 Go Installfest

http://localhost:3999/present.slide#34 23/35

Installation

go get github.com/gin-gonic/gin

Page 24: Go Installfest

9/25/2016 Go Installfest

http://localhost:3999/present.slide#34 24/35

Using

import "github.com/gin-gonic/gin"

package main import "github.com/gin-gonic/gin" func main() { // Creates a gin router with default middleware: // logger and recovery (crash-free) middleware router := gin.Default() router.GET("/someGet", getting) router.POST("/somePost", posting) router.PUT("/somePut", putting) router.DELETE("/someDelete", deleting) router.PATCH("/somePatch", patching) router.HEAD("/someHead", head) router.OPTIONS("/someOptions", options) // By default it serves on :8080 unless a // PORT environment variable was defined. router.Run() // router.Run(":3000") for a hard coded port }

Page 25: Go Installfest

9/25/2016 Go Installfest

http://localhost:3999/present.slide#34 25/35

Gorm

Page 26: Go Installfest

9/25/2016 Go Installfest

http://localhost:3999/present.slide#34 26/35

Introduction

ORM library

Developer friendly

Auto migration

Logger

Page 27: Go Installfest

9/25/2016 Go Installfest

http://localhost:3999/present.slide#34 27/35

Installation

go get -u github.com/jinzhu/gorm

Page 28: Go Installfest

9/25/2016 Go Installfest

http://localhost:3999/present.slide#34 28/35

Using

import "github.com/jinzhu/gorm"

import _ "github.com/lib/pq"

Page 29: Go Installfest

9/25/2016 Go Installfest

http://localhost:3999/present.slide#34 29/35

Code

type Product struct { gorm.Model Code string Price uint } func main() { db, err := gorm.Open("sqlite3", "test.db") if err != nil { panic("failed to connect database") } defer db.Close() db.AutoMigrate(&Product{}) db.Create(&Product{Code: "L1212", Price: 1000}) var product Product db.First(&product, "code = ?", "L1212") // find product with code l1212 db.Model(&product).Update("Price", 2000) db.Delete(&product) }

Page 30: Go Installfest

9/25/2016 Go Installfest

http://localhost:3999/present.slide#34 30/35

gRPC

Page 31: Go Installfest

9/25/2016 Go Installfest

http://localhost:3999/present.slide#34 31/35

Introduction

Distributed services and clients

Across languages

RPC

Protobuf

HTTP/2

Page 32: Go Installfest

9/25/2016 Go Installfest

http://localhost:3999/present.slide#34 32/35

Installation

go get google.golang.org/grpc

go get github.com/grpc/grpc-go

Page 33: Go Installfest

9/25/2016 Go Installfest

http://localhost:3999/present.slide#34 33/35

Using

De�ne a service in a .proto �le.

Generate server and client code using the protocol bu�er compiler.

Use the Go gRPC API to write a simple client and server for your service.

Page 34: Go Installfest

9/25/2016 Go Installfest

http://localhost:3999/present.slide#34 34/35

Thank you

Thach LeTriet [email protected] (mailto:[email protected])

[email protected] (mailto:[email protected])

Page 35: Go Installfest

9/25/2016 Go Installfest

http://localhost:3999/present.slide#34 35/35