Skip to content

Instantly share code, notes, and snippets.

@alexedwards
alexedwards / gist.go
Created August 9, 2019 08:32
ACME Autocert for Go
package main
import (
"crypto/tls"
"flag"
"fmt"
"log"
"net/http"
"time"
@alexedwards
alexedwards / go-update
Created November 22, 2023 14:53
Bash script for updating Go
#!/bin/bash
# Check if the version argument is provided
if [ $# -ne 1 ]; then
echo "Usage: $0 <go_version>"
exit 1
fi
# Version number provided as an argument
version="$1"
@alexedwards
alexedwards / go-update.sh
Last active November 2, 2023 08:59
Bash script to update Go on linux-amd64 (generated using Chat GPT)
#!/bin/bash
# Check if the version argument is provided
if [ $# -ne 1 ]; then
echo "Usage: $0 <go_version>"
exit 1
fi
# Version number provided as an argument
version="$1"
name: Audit
on:
push:
branches:
- main
pull_request:
branches:
- main
name: Audit and deploy
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
@alexedwards
alexedwards / main.go
Created November 10, 2020 10:20
JSON encoding benchmarks #2
package main
import (
"encoding/json"
"net/http"
)
func main() {}
func healthcheckHandlerMarshalIndent(w http.ResponseWriter, r *http.Request) {
@alexedwards
alexedwards / main.go
Created November 15, 2020 10:38
JSON decoding benchmarks
package main
import (
"encoding/json"
"io/ioutil"
"net/http"
)
func createMovieHandlerUnmarshal(w http.ResponseWriter, r *http.Request) {
var input struct {
@alexedwards
alexedwards / gist.go
Created April 27, 2019 17:00
SCS v2 Custom Middleware
package main
import (
"bytes"
"io"
"log"
"net/http"
"github.com/alexedwards/scs/v2"
)
@alexedwards
alexedwards / main.go
Last active September 22, 2022 19:08
Example of chaining middlware in Go
package main
import (
"io"
"log"
"mime"
"net/http"
"os"
"github.com/goji/httpauth"
@alexedwards
alexedwards / gist.go
Last active August 13, 2022 12:59
SCS v2 Multiple Sessions
package main
import (
"database/sql"
"fmt"
"log"
"net/http"
"time"
"github.com/alexedwards/scs/v2"