Skip to content

Instantly share code, notes, and snippets.

1.png gasp.png prometheus.png
1down.png gavel.gif promise.gif
1password.png gavel.png promptworks.png
1train.png gcp.png protoss.png
1up.png gentleman_parrot.gif psy.gif
2.png gentlemanparrot.gif psych.gif
2train.png getwellsoon.png psyduck.png
3.png ghost.gif pubsub.png
4.png ghostbusters.png pudina.jpg
49ers.jpg ghostbusters_pepe.jpg pug.gif
@kpurdon
kpurdon / get_go_mod_info.sh
Created December 11, 2020 22:53
get license and version information from a go modules
rm licenses.csv
touch licenses.csv
echo "name,url,version,license" >> licenses.csv
deps=$(go list -m -json all | jq -c .)
for dep in $deps; do
path=$(echo $dep | jq -r .Path)
if [[ "$path" == "github.com/syndio/syndio" ]]; then
continue
fi
@kpurdon
kpurdon / main.go
Created June 30, 2017 18:10
golang graceful server shutdown example
package main
import (
"context"
"flag"
"fmt"
"log"
"net/http"
"os"
"os/signal"
func TestAuth(t *testing.T) {
assert := assert.New(t)
tests := []struct {
description string
url string
expectedBody string
expectedCode int
}{
{
// GetTestHandler returns a http.HandlerFunc for testing http middleware
func GetTestHandler() http.HandlerFunc {
fn := func(rw http.ResponseWriter, req *http.Request) {
panic("test entered test handler, this should not happen")
}
return http.HandlerFunc(fn)
}
package main
import (
"log"
"net/http"
"github.com/gorilla/context"
)
var (
var c = ReposClient{}
func TestGet(t *testing.T) {
assert := assert.New(t)
httpmock.Activate()
defer httpmock.DeactivateAndReset()
tests := []struct {
description string
func TestGetReposHandler(t *testing.T) {
assert := assert.New(t)
tests := []struct {
description string
reposClient *ReposTestClient
url string
expectedStatusCode int
expectedBody string
}{
type ReposTestClient struct {
Repos []repos.Repo
Err error
}
func (c ReposTestClient) Get(string) ([]repos.Repo, error) {
return c.Repos, c.Err
}
type Client interface {
Get(string) ([]Repo, error)
}
type ReposClient struct{}
func (c ReposClient) Get(user string) ([]Repo, error) {
// call github api
}