func PostHordeGob(w http.ResponseWriter, r *http.Request) { gslog.Debug("HANDLER: PostHordeGob called with header: %+v, host: %s, requestURI: %s, remoteAddr: %s", r.Header, r.Host, r.RequestURI, r.RemoteAddr) params := r.URL.Query() hordeName := params.Get(":horde") if !validHordeName(hordeName) { returnHTTPError(w, "PostHordeGob", "horde name can only contain up to "+strconv.Itoa(HORDE_MAX_LEN)+" alphanumeric characters", http.StatusNotFound) return } gobData := getGobData(w, r) if len(gobData) == 0 { returnHTTPError(w, "PostHordeGob", "gob empty", http.StatusBadRequest) return } ip := getIpAddress(r) uid, token, err := store.PutHordeGob(hordeName, gobData, ip) gslog.Debug("HANDLER: uid: %s, ip: %s", uid, ip) if err != nil { gslog.Error("HANDLER: put horde gob failed with error: %s", err.Error()) returnHTTPError(w, "PostHordeGob", "failed to save gob", http.StatusInternalServerError) return } pageType := getPageType(r) pageBytes, err := templ.GetURLPage(getScheme(r), pageType, uid, token) w.Write(pageBytes) }
func PostGob(w http.ResponseWriter, r *http.Request) { gslog.Debug("HANDLER: PostGob called with header: %+v, host: %s, requestURI: %s, remoteAddr: %s", r.Header, r.Host, r.RequestURI, r.RemoteAddr) gobData := getGobData(w, r) if len(gobData) == 0 { returnHTTPError(w, "PostGob", "gob empty", http.StatusBadRequest) return } ip := getIpAddress(r) uid, token, err := store.PutGob(gobData, ip) gslog.Debug("HANDLER: PostGob uid: %s, ip: %s, token: %s", uid, ip, token) if err != nil { gslog.Error("HANDLER: post gob failed with error: %s", err.Error()) returnHTTPError(w, "PostGob", "failed to save gob", http.StatusInternalServerError) return } pageType := getPageType(r) pageBytes, err := templ.GetURLPage(getScheme(r), pageType, uid, token) if err != nil { gslog.Error("HANDLER: post gob failed with error: %s", err.Error()) returnHTTPError(w, "GetHorde", "failed to save gob", http.StatusInternalServerError) return } w.Write(pageBytes) }