Skip to content

Instantly share code, notes, and snippets.

I write code with my bare hands

Matt Holt mholt

I write code with my bare hands
View GitHub Profile
mholt / caddy-migrate-assets.go
Created Feb 22, 2021
Unsupported, ad-hoc program that migrates assets from Caddy v1 to Caddy v2
View caddy-migrate-assets.go
// Copyright 2021 Matthew Holt and The Caddy Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
mholt /
Created Oct 18, 2019 — forked from sleevi/
CT Best Practices (April 2017)

CT For Server (Developers)


Similar to my advice regarding OCSP Stapling for servers/server developers, based on questions I've received about "CT best practices," I wanted to write something similar for those writing server software. That is, this isn't targeted at server operators, but for those writing software like Apache, nginx, Caddy, etc.

At the most basic level, the deployment of Certificate Transparency to date has largely tried to focus the burden on CAs, rather than on server developers. If the CA is doing everything right,

View gen.go
// Handler that calls generate
func ok(w http.ResponseWriter, r *http.Request) {
// res := make([]int64, 0, 100000)
var res [100000]int64
// fmt.Println(suc)
// fmt.Printf("%T", res)
// fmt.Println(res[50])
fmt.Fprintf(w, "OK")
mholt /
Last active Jul 9, 2019
How do you like your handler configs?

Caddy 2 HTTP handlers come in two flavors: middleware and responders.

  • Middleware are in the middle of a request chain; i.e. they have a next handler to invoke.
  • Responders are content origins, at the end of a request chain; i.e. there is no next handler. Any handlers defined after it would not be invoked.

Caveat: Sometimes a handler's role is ambiguous. For example, a caching handler would be middleware on a cache miss (it needs to invoke the upstream handlers for a response, then cache it), but on a cache hit it would be a responder, since no further handlers would be invoked (it would simply write the response).

mholt / main.go
Created Oct 16, 2018 — forked from LiamHaworth/main.go
Example of run an interactive process on the current user from system service on windows (Golang)
View main.go
package main
import (
type Service struct {}
mholt / passwordpwned.go
Created Aug 12, 2018
Use Go to check if a password has been pwned
View passwordpwned.go
// checkPasswordPwned checks if the password is "pwned" according
// to the API offered by (The password
// is not sent to their servers to do the check.)
// This function returns the number of times the password appears in
// their data set. A password is pwned, or compromised, if the return
// value is greater than 0.
// API Docs:
mholt / macapp.go
Created May 18, 2018
Distribute your Go program (or any single binary) as a native macOS application
View macapp.go
// Package main is a sample macOS-app-bundling program to demonstrate how to
// automate the process described in this tutorial:
// Bundling the .app is the first thing it does, and creating the DMG is the
// second. Making the DMG is optional, and is only done if you provide
// the template DMG file, which you have to create beforehand.
// Example use:
mholt / apply-license.bash
Created Mar 27, 2018
Apply the Apache 2.0 license to all your .go files
View apply-license.bash
FILES=$(find . -name "*.go" -not -path "./vendor/*" -type f)
for f in $FILES
echo "processing: $f"
ed -s $f << EOF
// Copyright YEAR YOU
mholt / example.Caddyfile
Created Jun 21, 2017
restic plugin for Caddy
View example.Caddyfile
# specifying an empty root is not strictly necessary but not a bad
# idea if all you are serving on this site is the backups
root empty_www/
# authentication is required when using the Caddy plugin;
# this line assumes all requests are protected
basicauth / user pass
mholt / automate.go
Created May 6, 2017
The old automation program that produced Caddy builds for various platforms and bundled them into archives for distribution
View automate.go
// This program was used to build Caddy up to (but not including) v0.10.
// On April 20, 2017, it was replaced by a new releaser script that
// integrates with the autonomous build server. It bundles assets into
// an archive format that best fits the target OS. It could use `go build`
// to compile, but the way I configured it was to run the build.bash
// script that ensured the Caddy binary had proper version information
// embedded.
// I'm posting this here because it is no longer available in the Caddy
// repository and maybe you will find it useful for your own (simple?)