@@ -11,18 +11,21 @@ import (
1111 "net/http"
1212 "strings"
1313
14+ "github.com/tschaefer/rpinfo/server/log"
1415 "github.com/tschaefer/rpinfo/vcgencmd"
1516)
1617
1718type Handle struct {
1819 Cmd vcgencmd.Exec
1920}
2021
21- func runCmd (h Handle , w http.ResponseWriter , args ... string ) map [string ]string {
22- out := h .Cmd .Run (args ... )
23- if out = = nil {
22+ func runCmd (h Handle , w http.ResponseWriter , r * http. Request , args ... string ) map [string ]string {
23+ out , err := h .Cmd .Run (args ... )
24+ if err ! = nil {
2425 w .Header ().Set ("Content-Type" , "application/json" )
2526 w .WriteHeader (http .StatusInternalServerError )
27+
28+ go log .RequestError (r , http .StatusInternalServerError , err .Error ())
2629 json .NewEncoder (w ).Encode (map [string ]string {"detail" : "internal server error" })
2730 return nil
2831 }
@@ -31,46 +34,49 @@ func runCmd(h Handle, w http.ResponseWriter, args ...string) map[string]string {
3134}
3235
3336func (h Handle ) Temperature (w http.ResponseWriter , r * http.Request ) {
34- temp := runCmd (h , w , "measure_temp" )
37+ temp := runCmd (h , w , r , "measure_temp" )
3538 if temp == nil {
3639 return
3740 }
3841
42+ go log .RequestInfo (r , http .StatusOK , "Fetched temperature" )
3943 json .NewEncoder (w ).Encode (temp )
4044}
4145
4246func (h Handle ) Configuration (w http.ResponseWriter , r * http.Request ) {
4347 options := []string {"int" , "str" }
4448 config := make (map [string ]string )
4549 for _ , opt := range options {
46- out := runCmd (h , w , "get_config" , opt )
50+ out := runCmd (h , w , r , "get_config" , opt )
4751 if out == nil {
4852 return
4953 }
5054
5155 maps .Copy (config , out )
5256 }
5357
58+ go log .RequestInfo (r , http .StatusOK , "Fetched configuration" )
5459 json .NewEncoder (w ).Encode (config )
5560}
5661
5762func (h Handle ) Voltages (w http.ResponseWriter , r * http.Request ) {
5863 options := []string {"core" , "sdram_c" , "sdram_i" , "sdram_p" }
5964 voltages := make (map [string ]string )
6065 for _ , opt := range options {
61- out := runCmd (h , w , "measure_volts" , opt )
66+ out := runCmd (h , w , r , "measure_volts" , opt )
6267 if out == nil {
6368 return
6469 }
6570
6671 voltages [opt ] = out ["volt" ]
6772 }
6873
74+ go log .RequestInfo (r , http .StatusOK , "Fetched voltages" )
6975 json .NewEncoder (w ).Encode (voltages )
7076}
7177
7278func (h Handle ) Throttled (w http.ResponseWriter , r * http.Request ) {
73- throttled := runCmd (h , w , "get_throttled" )
79+ throttled := runCmd (h , w , r , "get_throttled" )
7480 if throttled == nil {
7581 return
7682 }
@@ -84,6 +90,7 @@ func (h Handle) Throttled(w http.ResponseWriter, r *http.Request) {
8490 throttled ["throttled" ] = message
8591 }
8692
93+ go log .RequestInfo (r , http .StatusOK , "Fetched throttled status" )
8794 json .NewEncoder (w ).Encode (throttled )
8895}
8996
@@ -95,7 +102,7 @@ func (h Handle) Clock(w http.ResponseWriter, r *http.Request) {
95102 }
96103 clock := make (map [string ]string )
97104 for _ , opt := range options {
98- out := runCmd (h , w , "measure_clock" , opt )
105+ out := runCmd (h , w , r , "measure_clock" , opt )
99106 if out == nil {
100107 return
101108 }
@@ -111,5 +118,6 @@ func (h Handle) Clock(w http.ResponseWriter, r *http.Request) {
111118 clock [opt ] = value ()
112119 }
113120
121+ go log .RequestInfo (r , http .StatusOK , "Fetched clock rates" )
114122 json .NewEncoder (w ).Encode (clock )
115123}
0 commit comments