Skip to content

Instantly share code, notes, and snippets.

View jamesmccann's full-sized avatar

James McCann jamesmccann

View GitHub Profile
@jamesmccann
jamesmccann / wrap-kms-key.sh
Created June 20, 2023 02:53
Wrap key for KMS manually
# Set in args
# TARGET_KEY=
# WRAPPING_KEY=
TEMP_AES_KEY=/tmp/TEMP_AES_KEY
WRAPPED_KEY=/tmp/WRAPPED_KEY
echo "WRAPPING_KEY: " ${WRAPPING_KEY}; \
echo "TARGET_KEY: " ${TARGET_KEY}; \
echo "TEMP_AES_KEY: " ${TEMP_AES_KEY}; \
@jamesmccann
jamesmccann / testutil.go
Last active March 15, 2023 20:42
Setting up a test postgres instance wrapped by your store interface in a Go app.
func NewStoreWithTestDatabase(ctx context.Context) (*store.Store, func() error, error) {
// uses a sensible default on windows (tcp/http) and linux/osx (socket)
pool, err := dockertest.NewPool("")
if err != nil {
return nil, nil, errs.Wrap(err, "could not construct pool", nil)
}
// uses pool to try to connect to Docker
err = pool.Client.Ping()
if err != nil {
// Middleware is a type alias for a function that
// accepts an http.Handler as the "next" handler in a chain
// and returns an http.Handler that will be executed before that handler.
type Middleware func(httprouter.Handle) httprouter.Handle
// MiddlewareChain represents a chain of middleware functions that can be
// assigned to wrap a handler function.
type MiddlewareChain []Middleware
// NewMiddlewareChain is a constructor for a chain of middlewares.
@jamesmccann
jamesmccann / Makefile
Last active August 5, 2019 07:26
modd live-reloading go server with .env config
dev:
env $$(grep -v '^#' .env | xargs) modd