31
GOLang & GoatCore

GoLang & GoatCore

Embed Size (px)

Citation preview

Page 1: GoLang & GoatCore

GOLang& GoatCore

Page 2: GoLang & GoatCore

Dlaczego powstał?

Page 7: GoLang & GoatCore

Jak zacząć

Page 8: GoLang & GoatCore

Krok 1● Zainstaluj mingw64● C_INCLUDE_PATH

● PATH

C:\Program Files\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\includeC:\Program Files\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\lib\gcc\mingw32\4.5.1\include

C:\Program Files\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\binC:\Program Files\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\libexec\gcc\x86_64-w64-mingw32\6.2.0

Page 9: GoLang & GoatCore

Krok 2● Zainstaluj golang● Zainstaluj git● Zainstaluj atom● Zainstaluj go-plus plugin (do atoma)● Zainstaluj postgresa (lub inną bazę w zależności od projektu)● Zainstaluj delve● Zainstaluj npm, yarn...

Page 10: GoLang & GoatCore

Krok 3● Zainstaluj biblioteki dla atoma

> go get -u golang.org/x/tools/cmd/goimports> go get -u golang.org/x/tools/cmd/gorename> go get -u github.com/sqs/goreturns> go get -u github.com/nsf/gocode> go get -u github.com/alecthomas/gometalinter> go get -u github.com/zmb3/gogetdoc> go get -u github.com/rogpeppe/godef> go get -u golang.org/x/tools/cmd/guru

Page 11: GoLang & GoatCore

Krok 4● Pobieramy projekt

> git clone github.com/goatcms/goatcore> git clone github.com/goatcms/goatcms

Page 12: GoLang & GoatCore

Krok 5● Pobieramy projekt

> cd github.com/goatcms/goatcms> go run ./main.go run --loglvl=dev

Page 13: GoLang & GoatCore

Jak zacząć szybciej

Page 14: GoLang & GoatCore

Pobieramy i odpalamy● Pobieramy github.com/goatcms/goatcms/devops/devtools

● Odpalamy

> docker-compose up

> git clone https://github.com/goatcms/goatcms.git

Page 15: GoLang & GoatCore

Czas na demo

Page 16: GoLang & GoatCore

Budowanie

Page 17: GoLang & GoatCore

Pobieramy i odpalamy● Odpalamy

● Budujemy #1

> go build .\main.go

> go run ./main.go run --loglvl=dev

Page 18: GoLang & GoatCore

Pobieramy i odpalamy● Budujemy #2

● Budujemy #3

> GOARM=6 GOARCH=arm GOOS=linux go build examples/raspi_blink.go

> go build -ldflags "-w" .\main.go

Page 19: GoLang & GoatCore

Dlaczego go jest odjechany

Page 21: GoLang & GoatCore

Kanałypackage main

import "fmt"

func main() {ch := make(chan int, 2)ch <- 1ch <- 2fmt.Println(<-ch)fmt.Println(<-ch)

}

Page 22: GoLang & GoatCore

Kanał & runtimefunc fibonacci(n int, c chan int) {

x, y := 0, 1for i := 0; i < n; i++ {

c <- xx, y = y, x+y

}close(c)

}

func main() {c := make(chan int, 10)go fibonacci(cap(c), c)for i := range c {

fmt.Println(i)}

}

Page 23: GoLang & GoatCore

Selectfunc main() {

tick := time.Tick(100 * time.Millisecond)boom := time.After(500 * time.Millisecond)for {

select {case <-tick:

fmt.Println("tick.")case <-boom:

fmt.Println("BOOM!")return

default:fmt.Println(" .")time.Sleep(50 * time.Millisecond)

}}

}

Page 24: GoLang & GoatCore

GoatCore

Page 25: GoLang & GoatCore

… iteracja po plikachfsloop.NewLoop(&fsloop.LoopData{

Filespace: fs,FileFilter: func(fs filesystem.Filespace, subPath string) bool {

return strings.HasSuffix(subPath, ".json")},OnFile: func(fs filesystem.Filespace, subPath string) error {

data, err := fs.ReadFile(subPath)if err != nil {

return err}tmap := map[string]string{}if err = LoadJSON("", tmap, data); err != nil {

return err}i18.Set(tmap)return nil

},}, scope).Run(basePath)

Page 26: GoLang & GoatCore

… iteracja po plikachfunc LoadJSON(resultKey string, result map[string]string, data []byte) error {

return jsonparser.ObjectEach(data, func(key []byte, value []byte, dataType jsonparser.ValueType, offset int) error {

var newResultKey stringif resultKey != "" {

newResultKey = resultKey + "." + string(key)} else {

newResultKey = string(key)}switch dataType {case jsonparser.Object:

return LoadJSON(newResultKey, result, value)case jsonparser.String:

result[newResultKey] = string(value)}return nil

})}

Page 27: GoLang & GoatCore

What makes it so fast?● It does not rely on encoding/json, reflection or interface{}, the only real

package dependency is bytes.● Operates with JSON payload on byte level, providing you pointers to the

original data structure: no memory allocation.● No automatic type conversions, by default everything is a []byte, but it

provides you value type, so you can convert by yourself (there is few helpers included).

● Does not parse full record, only keys you specified

- buger/jsonparser

Page 28: GoLang & GoatCore

Testujemy● Testy jednostkowe

● Testy wydajnościowe

> go test -v github.com/goatcms/goatcore/...

> cd github.com/goatcms/goatcore/i18n/fsi18loader> go test --bench=Linear --cpu=1,2,3,4,5,6,7,8,9,10

Page 29: GoLang & GoatCore

Pytania?

Page 30: GoLang & GoatCore

GoatCorehttps://github.com/goatcms/goatcore

Page 31: GoLang & GoatCore

Dziękuję za uwagę