Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env bash
set -e
cd /tmp
rm -rf /tmp/mock
mkdir /tmp/mock
cd /tmp/mock
git clone https://github.com/golang/mock mock-before
package main
import (
"fmt"
"log"
"gopkg.in/yaml.v2"
)
const withAlias = `foo:
@rgarcia
rgarcia / circuit_breakers.md
Last active October 20, 2022 07:18
go circuit breakers
func New(errorThreshold, successThreshold int, timeout time.Duration) *Breaker

New constructs a new circuit-breaker that starts closed. From closed, the breaker opens if "errorThreshold" errors are seen without an error-free period of at least "timeout". From open, the breaker half-closes after "timeout". From half-open, the breaker closes after "successThreshold" consecutive successes, or opens on a single error.

@rgarcia
rgarcia / main.go
Created September 19, 2016 23:56
net/http server context object does not cancel on closed connections, need to listen for closenotify
package main
import (
"context"
"fmt"
"log"
"net/http"
"time"
"golang.org/x/net/context/ctxhttp"
@rgarcia
rgarcia / diff.txt
Created March 26, 2016 23:06
ldclient-node eventsource patch
*** 171,176 ****
--- 171,177 ----
req.on('error', onConnectionClosed);
req.setNoDelay(true);
+ req.setSocketKeepAlive(true);
req.end();
}
@rgarcia
rgarcia / b.go
Created March 14, 2016 21:21
mocking a vendored dependency
// $GOPATH/src/a/vendor/b/b.go
package b
import "log"
type Type int
type Interface interface {
InterfaceMethod(Type)
}
@rgarcia
rgarcia / openvpn.json
Last active February 5, 2016 01:29
OpenVPN
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "Launch OpenVPN Server in an existing Virtual Private Cloud (VPC).",
"Parameters" : {
"InstanceType" : {
"Description" : "Instance type for OpenVPN Server",
"Type" : "String",
"Default" : "t2.micro",
"AllowedValues" : [ "t2.micro","t2.small","t2.medium","m3.medium","m3.large","m3.xlarge","m3.2xlarge"],
"ConstraintDescription" : "must be a valid EC2 instance type."
@rgarcia
rgarcia / vpc.json
Created February 5, 2016 01:10
VPC
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "VPC with two public subnets and two private subnets in different AZs, and a NAT to enable instances in private subnets to access the internet",
"Parameters" : {
"KeyName" : {
"Description" : "Name of an existing EC2 KeyPair to enable SSH access to the bastion host",
"Type" : "AWS::EC2::KeyPair::KeyName"
}
.PHONY: build run local-dev
build: $(wildcard ./**/*)
docker build -t myimage .
run:
docker run myimage
local-dev:
./local-dev.sh
@rgarcia
rgarcia / b.go
Created August 4, 2015 22:09
PkgPath bug?
// $GOPATH/src/a/vendor/b/b.go
package b
type B struct {
}