forked from ochinchina/supervisord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
confApi.go
47 lines (38 loc) · 1.07 KB
/
confApi.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"net/http"
"github.com/gorilla/mux"
)
type ConfApi struct {
router *mux.Router
supervisor *Supervisor
}
// NewLogtail creates a Logtail object
func NewConfApi(supervisor *Supervisor) *ConfApi {
return &ConfApi{router: mux.NewRouter(), supervisor: supervisor}
}
// CreateHandler creates http handlers to process the program stdout and stderr through http interface
func (ca *ConfApi) CreateHandler() http.Handler {
ca.router.HandleFunc("/conf/{program}", ca.getProgramConfFile).Methods("GET")
return ca.router
}
func (ca *ConfApi) getProgramConfFile(writer http.ResponseWriter, request *http.Request) {
vars := mux.Vars(request)
if vars == nil {
writer.WriteHeader(http.StatusNotFound)
return
}
programName := vars["program"]
programConfigPath := getProgramConfigPath(programName, ca.supervisor)
if programConfigPath == "" {
writer.WriteHeader(http.StatusNotFound)
return
}
b, err := readFile(programConfigPath)
if err != nil {
writer.WriteHeader(http.StatusNotFound)
return
}
writer.WriteHeader(http.StatusOK)
writer.Write(b)
}