u
Anirudh Oppiliappan x@icyphox.sh
Tue, 26 Sep 2023 20:17:12 +0300
3 files changed,
50 insertions(+),
3 deletions(-)
M
go.sum
→
go.sum
@@ -2,8 +2,6 @@ github.com/andybalholm/cascadia v1.3.2 h1:3Xi6Dw5lHF15JtdcmAHD3i1+T8plmv7BQ/nsViSLyss=
github.com/andybalholm/cascadia v1.3.2/go.mod h1:7gtRlve5FxPPgIgX36uWBX58OdBsSS6lUvCFb+h7KvU= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= -github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= -github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
A
masto_util.go
@@ -0,0 +1,50 @@
+package main + +import ( + "bytes" + "crypto/rand" + "fmt" + "log" + "net/http" + "time" + + "humungus.tedunangst.com/r/webs/junk" +) + +type NotResponseWriter struct { + body bytes.Buffer + header http.Header +} + +func (w NotResponseWriter) Header() http.Header { + return w.header +} + +func (w NotResponseWriter) Write(b []byte) (int, error) { + log.Println("actual code", string(b)) + return w.body.Write(b) +} + +func (w NotResponseWriter) WriteHeader(statusCode int) {} + +func snowflake() uint64 { + ts := time.Now() + return uint64(uint64(ts.UnixNano()/int64(time.Millisecond))<<16 | uint64(time.Now().Nanosecond()&0xffff)) +} + +func badjunk(rw http.ResponseWriter, j junk.Junk, path string) { + elog.Printf("%s: bad junk: %s", path, j.ToString()) + http.Error(rw, fmt.Sprintf("%s: bad junk", path), http.StatusBadRequest) +} + +func goodjunk(rw http.ResponseWriter, j junk.Junk) { + rw.WriteHeader(http.StatusOK) + rw.Header().Set("Content-Type", "application/json; charset=utf-8") + rw.Write(j.ToBytes()) +} + +func tokengen() string { + b := make([]byte, 32) + rand.Read(b) + return fmt.Sprintf("%x", b) +}