-
Notifications
You must be signed in to change notification settings - Fork 0
/
http-sstatus.go
45 lines (35 loc) · 1.08 KB
/
http-sstatus.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
// Copyright 2017 Inca Roads LLC. All rights reserved.
// Use of this source code is governed by licenses granted by the
// copyright holder including that found in the LICENSE file.
// Inbound support for the "/server/<instanceid>" HTTP topic
package main
import (
"fmt"
"io"
"net/http"
"os"
)
// Handle inbound HTTP requests to fetch log files
func inboundWebServerStatusHandler(rw http.ResponseWriter, req *http.Request) {
stats.Count.HTTP++
// Set response mime type
rw.Header().Set("Content-Type", "application/json")
// Log it
if req.RequestURI != TTServerStatusPath && len(req.RequestURI) > len(TTServerTopicServerStatus) {
filename := req.RequestURI[len(TTServerTopicServerStatus):]
if filename != "" {
fmt.Printf("%s Server information request for %s\n", LogTime(), filename)
// Open the file
file := SafecastDirectory() + TTServerStatusPath + "/" + filename + ".json"
fd, err := os.Open(file)
if err != nil {
io.WriteString(rw, ErrorString(err))
return
}
defer fd.Close()
// Copy the file to output
io.Copy(rw, fd)
return
}
}
}