Refactor application into multiple files

This commit is contained in:
2022-07-19 00:15:32 -06:00
parent 0139b08aae
commit bb9fe550ad
7 changed files with 486 additions and 417 deletions
+27
View File
@@ -0,0 +1,27 @@
package rest
import (
"fmt"
"net/http"
)
func setupHTTPServer(data_dir string) {
http.HandleFunc("/get_episodes", func(w http.ResponseWriter, r *http.Request) {
getEpisodesHandler(data_dir, w, r)
})
http.HandleFunc("/get_shows", func(w http.ResponseWriter, r *http.Request) {
getShowsHandler(data_dir, w, r)
})
}
func RunHTTPServer(address string, port int, data_dir string) {
setupHTTPServer(data_dir)
connect_string := fmt.Sprintf("%v:%v", address, port)
log.Noticef("Launching HTTP server on %v\n", connect_string)
log.Fatal(http.ListenAndServe(connect_string, nil))
}