Explorar o código

Remove execution method

poesty hai 9 meses
pai
achega
1b5818248e
Modificáronse 2 ficheiros con 38 adicións e 53 borrados
  1. 1 3
      config.json
  2. 37 50
      rss2hook.go

+ 1 - 3
config.json

@@ -1,14 +1,12 @@
 [
     {
         "url": "https://lorem-rss.herokuapp.com/feed?unit=second",
-        "method": "webhook",
         "retry": 5,
         "hook": "http://localhost:8080/"
     },
     {
         "url": "https://lorem-rss.herokuapp.com/feed?unit=minute&interval=1",
-        "method": "command",
         "retry": 5,
-        "hook": "ping"
+        "hook": "http://localhost:8080/"
     }
 ]

+ 37 - 50
rss2hook.go

@@ -1,6 +1,5 @@
 // rss2hook is a simple utility which will make HTTP POST
-// requests to remote web-hooks or execute commands when
-// new items appear in an RSS feed.
+// requests to remote web-hooks when new items appear in an RSS feed.
 //
 // Steve
 // poesty
@@ -16,7 +15,6 @@ import (
 	"log"
 	"net/http"
 	"os"
-	"os/exec"
 	"os/signal"
 	"reflect"
 	"syscall"
@@ -30,8 +28,6 @@ import (
 type RSSEntry struct {
 	// The URL of the RSS/Atom feed
 	Url string `json:"url,omitempty"`
-	// The hook method: webhook/command
-	Method string `json:"method,omitempty"`
 	// The retry count
 	Retry int `json:"retry,omitempty"`
 	// The hook end-point
@@ -103,56 +99,47 @@ func checkFeeds(feeds []rss.Feed) {
 	}
 }
 
-// notify submits the specified item to the remote webhook
-// or execute custom commands.
+// notify actually submits the specified item to the remote webhook.
 // The RSS-item is submitted as a JSON-object.
 func notify(i int, item *rss.Item) {
-	if Loaded[i].Method == "command" {
-		cmd := exec.Command(Loaded[i].Hook)
-		err := cmd.Start()
-		if err != nil {
-			log.Fatalf("notify: Failed to start command: %s\n", err.Error()) // TODO: retry?
-		}
-		// TODO: write outputs to files, and graceful shutdown
-	} else if Loaded[i].Method == "webhook" {
-		// We'll post the item as a JSON object.
-		// So first of all encode it.
-		jsonValue, err := json.Marshal(item)
-		if err != nil {
-			log.Fatalf("notify: Failed to encode JSON:%s\n", err.Error())
-		}
 
-		//
-		// Post to the specified hook URL.
-		//
-		res, err := http.Post(Loaded[i].Hook,
-			"application/json",
-			bytes.NewBuffer(jsonValue))
+	// We'll post the item as a JSON object.
+	// So first of all encode it.
+	jsonValue, err := json.Marshal(item)
+	if err != nil {
+		log.Fatalf("notify: Failed to encode JSON:%s\n", err.Error())
+	}
 
-		if err != nil {
-			log.Printf("notify: Failed to POST to %s - %s\n",
-				Loaded[i].Hook, err.Error()) // TODO: retry?
-			return
-		}
+	//
+	// Post to the specified hook URL.
+	//
+	res, err := http.Post(Loaded[i].Hook,
+		"application/json",
+		bytes.NewBuffer(jsonValue))
 
-		//
-		// OK now we've submitted the post.
-		//
-		// We should retrieve the status-code + body, if the status-code
-		// is "odd" then we'll show them.
-		//
-		defer res.Body.Close()
-		_, err = io.ReadAll(res.Body)
-		if err != nil {
-			log.Printf("notify: Failed to read response from %s - %s\n",
-				Loaded[i].Hook, err.Error())
-			return
-		}
-		status := res.StatusCode
+	if err != nil {
+		log.Printf("notify: Failed to POST to %s - %s\n",
+			Loaded[i].Hook, err.Error()) // TODO: retry?
+		return
+	}
 
-		if status != 200 {
-			log.Printf("notify: Warning - Status code was not 200: %d\n", status)
-		}
+	//
+	// OK now we've submitted the post.
+	//
+	// We should retrieve the status-code + body, if the status-code
+	// is "odd" then we'll show them.
+	//
+	defer res.Body.Close()
+	_, err = io.ReadAll(res.Body)
+	if err != nil {
+		log.Printf("notify: Failed to read response from %s - %s\n",
+			Loaded[i].Hook, err.Error())
+		return
+	}
+	status := res.StatusCode
+
+	if status != 200 {
+		log.Printf("notify: Warning - Status code was not 200: %d\n", status)
 	}
 }
 
@@ -199,7 +186,7 @@ func main() {
 					ent.Url, err.Error())
 				return
 			}
-			// TODO: validiy checks (webhook/command)
+			// TODO: URL validiy checks
 			// feed.Unread = 0
 			feeds[i] = *feed
 		}(i, ent)