Skip to content

Instantly share code, notes, and snippets.

@ismiyati
ismiyati / footgun.md
Created October 16, 2019 06:38 — forked from Rich-Harris/footgun.md
Top-level `await` is a footgun

Edit — February 2019

This gist had a far larger impact than I imagined it would, and apparently people are still finding it, so a quick update:

  • TC39 is currently moving forward with a slightly different version of TLA, referred to as 'variant B', in which a module with TLA doesn't block sibling execution. This vastly reduces the danger of parallelizable work happening in serial and thereby delaying startup, which was the concern that motivated me to write this gist
  • In the wild, we're seeing (async main(){...}()) as a substitute for TLA. This completely eliminates the blocking problem (yay!) but it's less powerful, and harder to statically analyse (boo). In other words the lack of TLA is causing real problems
  • Therefore, a version of TLA that solves the original issue is a valuable addition to the language, and I'm in full support of the current proposal, which you can read here.

I'll leave the rest of this document unedited, for archaeological

package main
import (
"fmt"
"net/http"
)
type Middleware func(http.HandlerFunc) http.HandlerFunc
func MiddlewareStack(mws ...Middleware) (handlerFunc http.HandlerFunc) {
package main
import (
"context"
"fmt"
"github.com/jackc/pgconn"
)
func main() {
@ismiyati
ismiyati / main.go
Last active October 1, 2019 16:44
#GOLANG . latihan go mod jika dependency package tidak di GOPATH/src dan supaya bisa pakai yang berada di local . referensi: https://dev.to/deepsource/package-management-in-go-4dhj https://ourcodeworld.com/articles/read/1049/how-to-migrate-go-modules-in-golang-projects
package main
import (
"domain.tld/username/pkg1"
)
func main() {
pkg1.Println("test")
}
@ismiyati
ismiyati / benchmark+go+nginx.md
Created September 10, 2019 06:14
Benchmarking Nginx with Go

Benchmarking Nginx with Go

There are a lot of ways to serve a Go HTTP application. The best choices depend on each use case. Currently nginx looks to be the standard web server for every new project even though there are other great web servers as well. However, how much is the overhead of serving a Go application behind an nginx server? Do we need some nginx features (vhosts, load balancing, cache, etc) or can you serve directly from Go? If you need nginx, what is the fastest connection mechanism? This are the kind of questions I'm intended to answer here. The purpose of this benchmark is not to tell that Go is faster or slower than nginx. That would be stupid.

So, these are the different settings we are going to compare:

  • Go HTTP standalone (as the control group)
  • Nginx proxy to Go HTTP
  • Nginx fastcgi to Go TCP FastCGI
  • Nginx fastcgi to Go Unix Socket FastCGI
package main
import (
"fmt"
"reflect"
"unsafe"
)
var data = []byte(`foobar`)
@ismiyati
ismiyati / udp-loader.go
Created September 8, 2019 01:14 — forked from jtblin/udp-loader.go
UDP server performance optimisation
package main
import (
"crypto/rand"
"flag"
"log"
mrand "math/rand"
"net"
"os"
"os/signal"
@ismiyati
ismiyati / chanLat1.go
Last active August 21, 2019 23:18
#golang unbufffered channel vs buffered channel
package main
import (
"fmt"
"time"
)
func main() {
fmt.Println("unbuffered channel:")
c1 := make(chan int) //unbuffered channel
go func(c chan int) {
@ismiyati
ismiyati / mergeMap.go
Last active August 14, 2019 12:04
#GOLANG merge map
package main
import (
"encoding/json"
"fmt"
)
type MapTree map[string]MapTree
func mergeMap(m0, m1 MapTree) {