move SendRecord from common to collect, minor make changes

pull/1/head^2
Simon Let 7 years ago
parent 1c13978684
commit da3d71e542
  1. 10
      Makefile
  2. 25
      collect/resh-collect.go
  3. 26
      common/resh-common.go
  4. 2
      daemon/resh-daemon.go

@ -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

@ -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 {

@ -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 :(")
}
}

@ -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() {

Loading…
Cancel
Save