From da3d71e5425899a4306502702c7eaee6047cc1df Mon Sep 17 00:00:00 2001 From: Simon Let Date: Wed, 15 May 2019 00:33:24 +0200 Subject: [PATCH] move SendRecord from common to collect, minor make changes --- Makefile | 10 +++++----- collect/resh-collect.go | 25 ++++++++++++++++++++++++- common/resh-common.go | 26 -------------------------- daemon/resh-daemon.go | 2 +- 4 files changed, 30 insertions(+), 33 deletions(-) diff --git a/Makefile b/Makefile index 06dc880..660b21f 100644 --- a/Makefile +++ b/Makefile @@ -29,9 +29,9 @@ $(HOME)/.resh/bin: .PHONY: submodules build install -submodules: submodules/bash-preexec/bash-preexec.sh - # this is always run and updates submodules - git submodule update --recursive +submodules: + # update (and intialize) submodules (recursively) + git submodule update --init --recursive -submodules/%: - git submodule init +submodules_to_latest_commit: + git submodule foreach --recursive git pull origin master diff --git a/collect/resh-collect.go b/collect/resh-collect.go index 2ee89fd..5bba328 100644 --- a/collect/resh-collect.go +++ b/collect/resh-collect.go @@ -1,9 +1,12 @@ package main import ( + "bytes" + "encoding/json" "os" "os/exec" "log" + "net/http" "strconv" "strings" common "github.com/curusarn/resh/common" @@ -24,7 +27,27 @@ func main() { Shell: os.Getenv("SHELL"), ExitCode: exitCode, } - rec.Send() + sendRecord(rec) +} + +func sendRecord(r common.Record) { + recJson, err := json.Marshal(r) + if err != nil { + log.Fatal("1 ", err) + } + + req, err := http.NewRequest("POST", "http://localhost:8888", + bytes.NewBuffer(recJson)) + if err != nil { + log.Fatal("2 ", err) + } + req.Header.Set("Content-Type", "application/json") + + client := &http.Client{} + _, err = client.Do(req) + if err != nil { + log.Fatal("resh-daemon is not running :(") + } } func getGitDir() string { diff --git a/common/resh-common.go b/common/resh-common.go index bf25fbf..9a18d47 100644 --- a/common/resh-common.go +++ b/common/resh-common.go @@ -1,12 +1,5 @@ package common -import ( - "bytes" - "encoding/json" - "net/http" - "log" -) - type Record struct { CmdLine string `json: cmdLine` Pwd string `json: pwd` @@ -16,22 +9,3 @@ type Record struct { Logs []string `json: logs` } -func (r Record) Send() { - recJson, err := json.Marshal(r) - if err != nil { - log.Fatal("1 ", err) - } - - req, err := http.NewRequest("POST", "http://localhost:8888", - bytes.NewBuffer(recJson)) - if err != nil { - log.Fatal("2 ", err) - } - req.Header.Set("Content-Type", "application/json") - - client := &http.Client{} - _, err = client.Do(req) - if err != nil { - log.Fatal("resh-daemon is not running :(") - } -} diff --git a/daemon/resh-daemon.go b/daemon/resh-daemon.go index 4782314..aacba0b 100644 --- a/daemon/resh-daemon.go +++ b/daemon/resh-daemon.go @@ -13,6 +13,7 @@ func main() { } func recordHandler(w http.ResponseWriter, r *http.Request) { + w.Write([]byte("OK\n")) record := common.Record{} jsn, err := ioutil.ReadAll(r.Body) @@ -32,7 +33,6 @@ func recordHandler(w http.ResponseWriter, r *http.Request) { // fmt.Println("pwd:", r.Pwd) // fmt.Println("git:", r.GitWorkTree) // fmt.Println("exit_code:", r.ExitCode) - w.Write([]byte("OK\n")) } func server() {