Skip to content

Instantly share code, notes, and snippets.

@birowo
birowo / README.MD
Last active June 11, 2018 04:24
golang: implementasi fungsi Marshal khusus untuk map & bukan untuk struct . playground: https://play.golang.org/p/nnyHUcCdyaA

fungsi Marshal di package encoding/json bisa di pakai baik untuk data type struct maupun data type map sehingga implementasinya harus pakai reflect: https://golang.org/src/encoding/json/encode.go?s=6456:6499#L298 . saya buat fungsi Marshal khusus untuk data type map saja & tidak untuk data type struct sehingga implementasinya bisa tanpa reflect sehingga performa bisa lebih baik

jsonmap

untuk cek kebenaran hasil, bisa pakai JSON.parse di konsol browser:

jsonmap_konsolbrowser

package main
import (
"net/http"
"github.com/julienschmidt/httprouter"
)
func Rutesku(notfound http.HandlerFunc, routers ...*httprouter.Router) (ret http.Handler) {
routersLen := len(routers)
@birowo
birowo / ruteku.go
Last active May 18, 2018 14:10
https://github.com/julienschmidt/httprouter sangat cepat, tetapi memiliki routing conflict : https://github.com/julienschmidt/httprouter/issues/175 . saya coba buat workaround pakai cara notfound chaining dari multiple router
package main
import (
"net/http"
"github.com/julienschmidt/httprouter"
)
type Ruteku struct {
httprouter.Router
@birowo
birowo / screenshot.md
Last active May 16, 2018 06:53
golang: server sent event

golang_sse

@birowo
birowo / _.sh
Created May 9, 2018 05:45 — forked from ikennaokpala/_.sh
Starting up and Monitoring a Golang binary in production
# Make it executable
sudo chmod +x etc/init.d/myapp
# Try it:
sudo service myapp start
# Make it run upon boot:
sudo update-rc.d myapp defaults
@birowo
birowo / screenshot.md
Last active May 7, 2018 03:55
golang : CRUD MySQL . mysql driver: https://github.com/go-sql-driver/mysql

crudmysql

@birowo
birowo / DependencyInjection.go
Last active April 29, 2018 23:42
golang: dependency injection(secara factory function), middleware, httprouter( https://github.com/julienschmidt/httprouter ), http.Server referensi: https://bash-shell.net/blog/dependency-injection-golang-http-middleware/ ,contoh skrip:
package main
import (
"fmt"
"net/http"
"github.com/julienschmidt/httprouter"
)
type mw func(httprouter.Handle) httprouter.Handle //middleware
package main
import (
"errors"
"fmt"
)
type tprop struct {
edge string
branch *Trie
package main
import (
_ "expvar"
"fmt"
"math/rand"
"sync"
"time"
)
package main
import (
"fmt"
"math/rand"
"sync"
"time"
)
func iterBlock(a, s []int, aLen, divLen, left int) {