Skip to content

Instantly share code, notes, and snippets.

@cbluth
cbluth / revproxy.go
Created February 5, 2024 09:34 — forked from dbrinegar/revproxy.go
transparent reverse proxy with basic auth and auto-follow
package main
import (
"log"
"net/http"
"net/http/httputil"
"net/url"
"gopkg.in/gcfg.v1"
)
@cbluth
cbluth / gist.go
Created October 12, 2023 08:27 — forked from alexedwards/gist.go
ACME Autocert for Go
package main
import (
"crypto/tls"
"flag"
"fmt"
"log"
"net/http"
"time"
@cbluth
cbluth / file_response_writer.go
Created March 22, 2020 08:52 — forked from ismasan/file_response_writer.go
Write backend HTTP response to http.ResponseWriter and File
// fileResponseWriter wraps an http.ResponseWriter and a File
// passing it to an http.Handler's ServeHTTP
// will write to both the file and the response.
type fileResponseWriter struct {
file io.Writer
resp http.ResponseWriter
multi io.Writer
}
@cbluth
cbluth / pocketbase.go
Created June 8, 2023 11:44 — forked from cnjax/pocketbase.go
fix for auth admin with password
package pocketbase
import (
"errors"
"fmt"
"github.com/duke-git/lancet/v2/convertor"
"github.com/go-resty/resty/v2"
"golang.org/x/sync/singleflight"
"time"
)
package main
import (
"bufio"
"io"
"os"
"os/exec"
"time"
"fyne.io/fyne/v2"
@cbluth
cbluth / debian-strongswan.md
Created November 10, 2022 11:38 — forked from andrewlkho/debian-strongswan.md
Setting up a secure VPN with strongSwan on debian

With heightening concern regarding the state of internet privacy (fuelled in part by the passing of the Investigatory Powers Act in the UK), I have set up a VPN server on the virtual server I have hosted with Mythic Beasts. This uses strongSwan and certificate-based IKEv2 authentication.

Assumptions:

  • Debian Jessie server already set up and accessible via debian.example.com, a public IPv4 of 203.0.113.1 and a public IPv6 of 2001:db8::1
  • Client username of me
  • Clients are running the latest versions of macOS and iOS (Sierra and 10 respectively at the time of writing)
  • No need to support any other operating systems (although the setup is easily translated)

For automated deployment of a similar setup, albeit Ubuntu-based and using ansible for deployment, I recommend you take a look at Algo VPN. I used that project as a basis for my configuration.

@cbluth
cbluth / unixhttpc.go
Created February 12, 2022 21:09 — forked from teknoraver/unixhttpc.go
HTTP over Unix domain sockets in golang
package main
import (
"context"
"flag"
"fmt"
"io"
"net"
"net/http"
"os"

How to setup a practically free CDN

I've been using [Backblaze][bbz] for a while now as my online backup service. I have used a few others in the past. None were particularly satisfactory until Backblaze came along.

It was - still is - keenly priced at a flat $5 (£4) per month for unlimited backup (I've currently got just under half a terabyte backed-up). It has a fast, reliable client. The company itself is [transparent about their operations][trans] and [generous with their knowledge sharing][blog]. To me, this says they understand their customers well. I've never had reliability problems and everything about the outfit exudes a sense of simple, quick, solid quality. The service has even saved the day on a couple of occasions where I've lost files.

Safe to say, I'm a happy customer. If you're not already using Backblaze, [I highly recommend you do][recommend].

Taking on the big boys with B2

@cbluth
cbluth / 1_simple.go
Created November 29, 2021 12:14 — forked from sosedoff/1_simple.go
Golang Custom Struct Tags Example
package main
import (
"fmt"
"reflect"
)
// Name of the struct tag used in examples
const tagName = "validate"
@cbluth
cbluth / validators.go
Created November 29, 2021 12:14 — forked from dakait/validators.go
Golang Custom Validator examples
package main
import (
"fmt"
"github.com/satori/go.uuid" //for uuid
"gopkg.in/validator.v2"
"reflect"
"regexp"
"time"
)