Upload
sebastian-pozoga
View
141
Download
0
Embed Size (px)
Citation preview
GOLang& GoatCore
Dlaczego powstał?
Jak zacząć
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
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...
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
Krok 4● Pobieramy projekt
> git clone github.com/goatcms/goatcore> git clone github.com/goatcms/goatcms
Krok 5● Pobieramy projekt
> cd github.com/goatcms/goatcms> go run ./main.go run --loglvl=dev
Jak zacząć szybciej
Pobieramy i odpalamy● Pobieramy github.com/goatcms/goatcms/devops/devtools
● Odpalamy
> docker-compose up
> git clone https://github.com/goatcms/goatcms.git
Czas na demo
Budowanie
Pobieramy i odpalamy● Odpalamy
● Budujemy #1
> go build .\main.go
> go run ./main.go run --loglvl=dev
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
Dlaczego go jest odjechany
“Concurrency Is Not Parallelism”- Rob Pike
Kanałypackage main
import "fmt"
func main() {ch := make(chan int, 2)ch <- 1ch <- 2fmt.Println(<-ch)fmt.Println(<-ch)
}
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)}
}
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)
}}
}
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)
… 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
})}
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
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
Pytania?
GoatCorehttps://github.com/goatcms/goatcore
Dziękuję za uwagę