Skip to content

Instantly share code, notes, and snippets.

View minitauros's full-sized avatar

Stephan minitauros

View GitHub Profile
@minitauros
minitauros / decode_json_response.go
Last active July 26, 2022 09:30
Decode a JSON response while also adding the JSON response body to the unmarshalling error.
// DecodeJSONResp decodes the body of the given response into the given target.
// If an error occurs, instead of only returning the unmarshaling error, the error will also contain the first 100 chars
// of the response JSON. This allows for better debugging.
func DecodeJSONResp(resp *http.Response, target interface{}) error {
pr, pw := io.Pipe()
tr := io.TeeReader(resp.Body, pw)
respCh := make(chan string)
errCh := make(chan error)
go func() {
@minitauros
minitauros / denv
Last active April 19, 2023 15:53
Quickly switch direnv env vars
#!/bin/bash
#
# For easily switching between .envrc files.
#
# This allows you to have and use multiple .envrc files in the same
# directory, like .envrc.test, .envrc.local and .envrc.prod.
#
# Usage:
#
# denv [extension]