gofmt daemon

pull/3/head
Simon Let 7 years ago
parent 3b90a42240
commit bf9167e96a
  1. 55
      daemon/resh-daemon.go

@ -3,17 +3,17 @@ package main
import ( import (
"encoding/json" "encoding/json"
//"flag" //"flag"
"log" "github.com/BurntSushi/toml"
common "github.com/curusarn/resh/common"
"io/ioutil" "io/ioutil"
"path/filepath" "log"
"net/http"
"os" "os"
"os/exec" "os/exec"
"os/user" "os/user"
"path/filepath"
"strconv" "strconv"
"strings" "strings"
"net/http"
common "github.com/curusarn/resh/common"
"github.com/BurntSushi/toml"
) )
func main() { func main() {
@ -24,7 +24,7 @@ func main() {
outputPath := filepath.Join(dir, ".resh/history.json") outputPath := filepath.Join(dir, ".resh/history.json")
logPath := filepath.Join(dir, ".resh/daemon.log") logPath := filepath.Join(dir, ".resh/daemon.log")
f, err := os.OpenFile(logPath, os.O_RDWR | os.O_CREATE | os.O_APPEND, 0644) f, err := os.OpenFile(logPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
if err != nil { if err != nil {
log.Fatal("Error opening file:", err) log.Fatal("Error opening file:", err)
} }
@ -114,7 +114,7 @@ func (h *recordHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
func runServer(port int, outputPath string) { func runServer(port int, outputPath string) {
http.HandleFunc("/status", statusHandler) http.HandleFunc("/status", statusHandler)
http.Handle("/record", &recordHandler{OutputPath: outputPath}) http.Handle("/record", &recordHandler{OutputPath: outputPath})
http.ListenAndServe(":" + strconv.Itoa(port) , nil) http.ListenAndServe(":"+strconv.Itoa(port), nil)
} }
func killDaemon(pidfile string) error { func killDaemon(pidfile string) error {
@ -140,7 +140,7 @@ func isDaemonRunning(port int) (bool, error) {
url := "http://localhost:" + strconv.Itoa(port) + "/status" url := "http://localhost:" + strconv.Itoa(port) + "/status"
resp, err := http.Get(url) resp, err := http.Get(url)
if err != nil { if err != nil {
log.Println("Error while checking daemon status - " + log.Println("Error while checking daemon status - "+
"it's probably not running!", err) "it's probably not running!", err)
return false, err return false, err
} }
@ -148,24 +148,23 @@ func isDaemonRunning(port int) (bool, error) {
return true, nil return true, nil
//body, err := ioutil.ReadAll(resp.Body) //body, err := ioutil.ReadAll(resp.Body)
// dat, err := ioutil.ReadFile(pidfile)
// dat, err := ioutil.ReadFile(pidfile) // if err != nil {
// if err != nil { // log.Println("Reading pid file failed", err)
// log.Println("Reading pid file failed", err) // return false, err
// return false, err // }
// } // log.Print(string(dat))
// log.Print(string(dat)) // pid, err := strconv.ParseInt(string(dat), 10, 64)
// pid, err := strconv.ParseInt(string(dat), 10, 64) // if err != nil {
// if err != nil { // log.Fatal(err)
// log.Fatal(err) // }
// } // process, err := os.FindProcess(int(pid))
// process, err := os.FindProcess(int(pid)) // if err != nil {
// if err != nil { // log.Printf("Failed to find process: %s\n", err)
// log.Printf("Failed to find process: %s\n", err) // return false, err
// return false, err // } else {
// } else { // err := process.Signal(syscall.Signal(0))
// err := process.Signal(syscall.Signal(0)) // log.Printf("process.Signal on pid %d returned: %v\n", pid, err)
// log.Printf("process.Signal on pid %d returned: %v\n", pid, err) // }
// } // return true, nil
// return true, nil
} }

Loading…
Cancel
Save