Skip to content

Instantly share code, notes, and snippets.

View wrunk's full-sized avatar

Warren Runk wrunk

View GitHub Profile
@wrunk
wrunk / GolangJSONCustomMarshal.go
Created October 12, 2016 22:59
Golang JSON Custom Marshal
/*
In a fairly typical webapp data model you often want to send
the client different "views" of the data model.
Many database and caching tools require the base model to be quite
standard with json tags and types, so the following approach is
ideal:
Based on this blog post and SO question:
@wrunk
wrunk / pre-commit
Created October 28, 2016 18:24
Golang git pre commit hook
#!/bin/sh
#
# Note this is mostly the standard git pre-commit.sample which can be found
# in your repo's .git/hooks/ directory with golang fmt added at the bottom.
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
@wrunk
wrunk / user_test.go
Last active January 25, 2021 23:34
Golang unit test for panic scenario
func TestUserFail(t *testing.T) {
func() {
defer func() {
if r := recover(); r == nil {
t.Errorf("TestUserFail should have panicked!")
}
}()
// This function should cause a panic
CreateUser(12, "hello")