Cleanup errors and documentation
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Peter Stuifzand 2019-03-19 21:55:07 +01:00
parent ea6d779d4e
commit 1e0f192ab4
Signed by: peter
GPG Key ID: 374322D56E5209E8
3 changed files with 17 additions and 56 deletions

View File

@ -1,20 +1,3 @@
/*
ekster - microsub server
Copyright (C) 2018 Peter Stuifzand
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package main
import (
@ -116,10 +99,15 @@ func setCachedTokenResponseValue(conn redis.Conn, key string, r *auth.TokenRespo
// getCachedValue gets the cached value from Redis
func getCachedValue(conn redis.Conn, key string, r *auth.TokenResponse) (bool, error) {
values, err := redis.Values(conn.Do("HGETALL", key))
if err == nil && len(values) > 0 {
if err != nil {
return false, fmt.Errorf("error while getting value from backend: %v", err)
}
if len(values) > 0 {
if err = redis.ScanStruct(values, r); err == nil {
return true, nil
}
}
return false, fmt.Errorf("error while getting value from backend: %v", err)
return false, fmt.Errorf("no cached value available")
}

View File

@ -1,20 +1,3 @@
/*
ekster - microsub server
Copyright (C) 2018 Peter Stuifzand
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package main
import (
@ -50,6 +33,7 @@ type hubIncomingBackend struct {
baseURL string
}
// Feed contains information about the feed subscriptions
type Feed struct {
ID int64 `redis:"id"`
Channel string `redis:"channel"`
@ -214,7 +198,7 @@ func (h *hubIncomingBackend) run() error {
if feed.Callback == "" {
feed.Callback = fmt.Sprintf("%s/incoming/%d", h.baseURL, feed.ID)
}
log.Printf("Send resubscribe for %q on %q\n", feed.URL, feed.Hub)
log.Printf("Send resubscribe for %q on %q with callback %q\n", feed.URL, feed.Hub, feed.Callback)
err := h.Subscribe(&feed)
if err != nil {
log.Printf("Error while subscribing: %s", err)

View File

@ -1,20 +1,3 @@
/*
Microsub server
Copyright (C) 2018 Peter Stuifzand
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package main
import (
@ -41,7 +24,12 @@ var (
func (h *incomingHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
r.ParseForm()
err := r.ParseForm()
if err != nil {
http.Error(w, "could not parse form data", http.StatusBadRequest)
return
}
log.Printf("%s %s\n", r.Method, r.URL)
log.Println(r.URL.Query())
log.Println(r.PostForm)
@ -73,7 +61,8 @@ func (h *incomingHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
verify := values.Get("hub.challenge")
fmt.Fprint(w, verify)
_, err := fmt.Fprint(w, verify)
http.Error(w, fmt.Sprintf("could not write verification challenge: %v", err), 400)
return
}