summaryrefslogtreecommitdiffstats
path: root/hyper/process/main.go
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2011-09-20 17:19:25 +0200
committermakefu <github@syntax-fehler.de>2011-09-20 17:19:25 +0200
commit32ddd0b2dec60ac99e30e26819e4653ccc47690e (patch)
tree6745bd80ed8392f0165a026215268ca24d3ce5c5 /hyper/process/main.go
parentdfadcd3b21d838c9d1bb8fc37304cec71e7517d8 (diff)
parentfcbb481cbd888d6ab66b09e649c754a012198e53 (diff)
Merge branch 'master' of github.com:krebscode/painload
Diffstat (limited to 'hyper/process/main.go')
-rw-r--r--hyper/process/main.go92
1 files changed, 46 insertions, 46 deletions
diff --git a/hyper/process/main.go b/hyper/process/main.go
index 5420f681..214dade9 100644
--- a/hyper/process/main.go
+++ b/hyper/process/main.go
@@ -10,68 +10,68 @@ import "bytes"
import "hyper/process"
-var proc = map[string] *hyper.Process{}
+var proc = map[string]*hyper.Process{}
// TODO Retrieve Process, Write, Kill [autokill], get exit code
func RespondJSON(res http.ResponseWriter, v interface{}) os.Error {
- content, err := json.Marshal(v)
- if err == nil {
- log.Printf("< %s", content)
- res.Header().Set("Content-Type", "application/json; charset=\"utf-8\"")
- res.WriteHeader(http.StatusOK)
- res.Write(content)
- } else {
- log.Printf("%s while json.Marshal(%s)", err, v)
- }
- return err
+ content, err := json.Marshal(v)
+ if err == nil {
+ log.Printf("< %s", content)
+ res.Header().Set("Content-Type", "application/json; charset=\"utf-8\"")
+ res.WriteHeader(http.StatusOK)
+ res.Write(content)
+ } else {
+ log.Printf("%s while json.Marshal(%s)", err, v)
+ }
+ return err
}
func CreateProcessHandler(res http.ResponseWriter, req *http.Request) {
- if p, err := hyper.NewProcess(req); err == nil {
- id := p.Id()
- proc[id] = p
- RespondJSON(res, &map[string]string{
- "path": fmt.Sprintf("/proc/%s", id),
- })
- } else {
- log.Printf("%s", err)
- res.WriteHeader(http.StatusInternalServerError)
- }
+ if p, err := hyper.NewProcess(req); err == nil {
+ id := p.Id()
+ proc[id] = p
+ RespondJSON(res, &map[string]string{
+ "path": fmt.Sprintf("/proc/%s", id),
+ })
+ } else {
+ log.Printf("%s", err)
+ res.WriteHeader(http.StatusInternalServerError)
+ }
}
func RetrieveProcess(res http.ResponseWriter, req *http.Request) {
- if p := proc[mux.Vars(req)["id"]]; p != nil {
- RespondJSON(res, p)
- } else {
- res.WriteHeader(http.StatusNotFound)
- }
+ if p := proc[mux.Vars(req)["id"]]; p != nil {
+ RespondJSON(res, p)
+ } else {
+ res.WriteHeader(http.StatusNotFound)
+ }
}
func FeedProcess(res http.ResponseWriter, req *http.Request) {
- if p := proc[mux.Vars(req)["id"]]; p != nil {
- body := make([]byte, 4096)
- if _, err := req.Body.Read(body); err == nil {
- body = bytes.TrimRight(body, string([]byte{0}))
- p.Write(body)
- //if err := p.Write(body); err == nil {
- RespondJSON(res, true)
- //}
- }
- } else {
- res.WriteHeader(http.StatusNotFound)
- }
+ if p := proc[mux.Vars(req)["id"]]; p != nil {
+ body := make([]byte, 4096)
+ if _, err := req.Body.Read(body); err == nil {
+ body = bytes.TrimRight(body, string([]byte{0}))
+ p.Write(body)
+ //if err := p.Write(body); err == nil {
+ RespondJSON(res, true)
+ //}
+ }
+ } else {
+ res.WriteHeader(http.StatusNotFound)
+ }
}
func main() {
- // Gorilla
- mux.HandleFunc("/proc", CreateProcessHandler).Methods("POST")
- mux.HandleFunc("/proc/{id}", RetrieveProcess).Methods("GET")
- mux.HandleFunc("/proc/{id}", FeedProcess).Methods("POST")
+ // Gorilla
+ mux.HandleFunc("/proc", CreateProcessHandler).Methods("POST")
+ mux.HandleFunc("/proc/{id}", RetrieveProcess).Methods("GET")
+ mux.HandleFunc("/proc/{id}", FeedProcess).Methods("POST")
- err := http.ListenAndServe("0.0.0.0:8888", mux.DefaultRouter)
- if err != nil {
- log.Fatal("ListenAndServe: ", err.String())
- }
+ err := http.ListenAndServe("0.0.0.0:8888", mux.DefaultRouter)
+ if err != nil {
+ log.Fatal("ListenAndServe: ", err.String())
+ }
}