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) }