Skip to content

Instantly share code, notes, and snippets.

View WrapResponseWriter.go
// NewWrapResponseWriter wraps an http.ResponseWriter, returning a proxy that allows you to
// hook into various parts of the response process.
func NewWrapResponseWriter(w http.ResponseWriter, protoMajor int) WrapResponseWriter {
_, fl := w.(http.Flusher)
bw := basicWriter{ResponseWriter: w}
if protoMajor == 2 {
_, ps := w.(http.Pusher)
if fl && ps {
@ribice
ribice / trim-nulls.go
Last active Feb 17, 2021
Remove null values from JSON with Golang - https://www.ribice.ba/golang-null-values/
View trim-nulls.go
func removeNulls(m map[string]interface{}) {
val := reflect.ValueOf(m)
for _, e := range val.MapKeys() {
v := val.MapIndex(e)
if v.IsNil() {
delete(m, e.String())
continue
}
switch t := v.Interface().(type) {
// If key is a JSON object (Go Map), use recursion to go deeper
@ribice
ribice / caller.go
Last active May 8, 2021
A robust rabbitmq client for Go
View caller.go
go func() {
for {
err = rmq.Stream(cancelCtx)
if errors.Is(err, rabbitmq.ErrDisconnected) {
continue
}
break
}
}()
@ribice
ribice / main.go
Created Feb 3, 2020
Golang map used for concurrent read/write
View main.go
package main
import (
"fmt"
"sync"
"time"
)
var countryCities = map[string][]string{}
var mutex = &sync.RWMutex{}
@ribice
ribice / log.go
Created Jan 18, 2020
Golang logging middleware
View log.go
package log
import (
"context"
"net/http"
"net/http/httptest"
"net/http/httputil"
"os"
"time"
@ribice
ribice / httperr.go
Created Jan 18, 2020
Handling http errors in Go
View httperr.go
package httpresp
import (
"context"
"fmt"
"net/http"
"github.com/go-chi/render"
"github.com/go-pg/pg/v9"
View keybase.md

Keybase proof

I hereby claim:

  • I am ribice on github.
  • I am ribice (https://keybase.io/ribice) on keybase.
  • I have a public key ASClwYeNkzBrC3mcLbp7Lc4Uf7DIo_SKsbbIQ1FGHi2nQgo

To claim this, I am signing this object: