package main import ( "crypto/rand" "fmt" "net/http" "time" "humungus.tedunangst.com/r/webs/junk" ) type NotResponseWriter struct { auth string header http.Header status int } func (w *NotResponseWriter) Header() http.Header { return w.header } func (w *NotResponseWriter) Write(b []byte) (int, error) { dlog.Println("notresponsewriter: oauth code:", string(b)) w.auth = string(b) return 0, nil } func (w *NotResponseWriter) WriteHeader(statusCode int) { w.status = statusCode } 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.Header().Set("Content-Type", "application/json; charset=utf-8") rw.WriteHeader(http.StatusOK) rw.Write(j.ToBytes()) } func tokengen() string { b := make([]byte, 32) rand.Read(b) return fmt.Sprintf("%x", b) }