Added reload function
This commit is contained in:
parent
6acad26f07
commit
04a5024064
|
@ -45,6 +45,7 @@ func main() {
|
|||
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/pepe", app.sendPepe)
|
||||
mux.HandleFunc("/reload", app.reloadList)
|
||||
|
||||
app.infoLog.Printf("Starting server at :4000\n")
|
||||
err = http.ListenAndServe(":4000", mux)
|
||||
|
@ -63,3 +64,21 @@ func (app *application) sendPepe(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
w.Write([]byte(URL))
|
||||
}
|
||||
|
||||
func (app *application) reloadList(w http.ResponseWriter, r *http.Request) {
|
||||
file, err := os.Open(app.pepe_dir)
|
||||
if err != nil {
|
||||
app.errorLog.Printf("Error opening pepe directory\n")
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
pepe_list, err := file.Readdirnames(0)
|
||||
if err != nil {
|
||||
app.errorLog.Printf("Error reading pepe directory file names\n")
|
||||
return
|
||||
}
|
||||
app.pepe_list = pepe_list
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte("200 - Reloaded the list of pepes"))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue