app.go (1490:cecf6b11a1e3) app.go (1707:d718554dd379)
1package main
2
3import (
4 "encoding/json"
5 "fmt"
6 "net/http"
7 "unit.nginx.org/go"
8 "os"
9 "strconv"
1package main
2
3import (
4 "encoding/json"
5 "fmt"
6 "net/http"
7 "unit.nginx.org/go"
8 "os"
9 "strconv"
10 "io/ioutil"
10)
11
12type (
13 NS struct {
14 USER uint64
15 PID uint64
16 IPC uint64
17 CGROUP uint64
18 UTS uint64
19 MNT uint64
20 NET uint64
21 }
22
23 Output struct {
24 PID int
25 UID int
26 GID int
27 NS NS
28 FileExists bool
11)
12
13type (
14 NS struct {
15 USER uint64
16 PID uint64
17 IPC uint64
18 CGROUP uint64
19 UTS uint64
20 MNT uint64
21 NET uint64
22 }
23
24 Output struct {
25 PID int
26 UID int
27 GID int
28 NS NS
29 FileExists bool
30 Mounts string
29 }
30)
31
32func abortonerr(err error) {
33 if err != nil {
34 panic(err)
35 }
36}

--- 35 unchanged lines hidden (view full) ---

72 return
73 }
74
75 if fname := r.Form.Get("file"); fname != "" {
76 _, err = os.Stat(fname);
77 out.FileExists = err == nil
78 }
79
31 }
32)
33
34func abortonerr(err error) {
35 if err != nil {
36 panic(err)
37 }
38}

--- 35 unchanged lines hidden (view full) ---

74 return
75 }
76
77 if fname := r.Form.Get("file"); fname != "" {
78 _, err = os.Stat(fname);
79 out.FileExists = err == nil
80 }
81
82 if mounts := r.Form.Get("mounts"); mounts != "" {
83 data, _ := ioutil.ReadFile("/proc/self/mountinfo")
84 out.Mounts = string(data)
85 }
86
80 data, err := json.Marshal(out)
81 if err != nil {
82 w.WriteHeader(http.StatusInternalServerError)
83 return
84 }
85
86 w.Header().Add("Content-Type", "application/json")
87
88 w.Write(data)
89}
90
91func main() {
92 http.HandleFunc("/", handler)
93 unit.ListenAndServe(":7080", nil)
94}
87 data, err := json.Marshal(out)
88 if err != nil {
89 w.WriteHeader(http.StatusInternalServerError)
90 return
91 }
92
93 w.Header().Add("Content-Type", "application/json")
94
95 w.Write(data)
96}
97
98func main() {
99 http.HandleFunc("/", handler)
100 unit.ListenAndServe(":7080", nil)
101}