github.com/Cloud-Foundations/Dominator@v0.3.4/hypervisor/httpd/showLastPatchLog.go (about) 1 package httpd 2 3 import ( 4 "bufio" 5 "io" 6 "net" 7 "net/http" 8 9 "github.com/Cloud-Foundations/Dominator/lib/url" 10 ) 11 12 func (s state) showLastPatchLogHandler(w http.ResponseWriter, 13 req *http.Request) { 14 parsedQuery := url.ParseQuery(req.URL) 15 if len(parsedQuery.Flags) != 1 { 16 w.Header().Set("Content-Type", "text/plain; charset=utf-8") 17 w.WriteHeader(http.StatusBadRequest) 18 return 19 } 20 var ipAddr string 21 for name := range parsedQuery.Flags { 22 ipAddr = name 23 } 24 r, _, _, err := s.manager.GetVmLastPatchLog(net.ParseIP(ipAddr)) 25 if err != nil { 26 w.Header().Set("Content-Type", "text/plain; charset=utf-8") 27 w.WriteHeader(http.StatusNotFound) 28 return 29 } 30 defer r.Close() 31 writer := bufio.NewWriter(w) 32 defer writer.Flush() 33 io.Copy(writer, r) 34 }