diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e431d99 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +catserver diff --git a/css/main.css b/css/main.css new file mode 100644 index 0000000..81202e0 --- /dev/null +++ b/css/main.css @@ -0,0 +1 @@ +ade diff --git a/css/test.css b/css/test.css new file mode 100644 index 0000000..81202e0 --- /dev/null +++ b/css/test.css @@ -0,0 +1 @@ +ade diff --git a/main.go b/main.go index f57bc52..1fd3bd6 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,53 @@ package main -import "fmt" +import ( + "io" + "log" + "net/http" + "os" + + "github.com/gorilla/mux" +) func main() { - fmt.Println("Initial commit") + r := mux.NewRouter() + + //TODO Take a look at https://github.com/gorilla/mux/issues/82 to hot-swap the routes in the config file + + // parse config file here + // if has grandchildren; then + // create subrouter + // else + // create routes + // + + // For initial testing, will use io writer on hardcoded paths: + // - css + // - styles.css + // - css/main.css + // - css/test.css + + r.HandleFunc("/css/styles.css", func(w http.ResponseWriter, r *http.Request) { + arr := [2]string{"css/main.css", "css/test.css"} + var readers []io.Reader + var files []*os.File + for _, x := range arr { + file, err := os.Open(x) + if err != nil { + //TODO: Proper error handling + panic(err) + } + readers = append(readers, file) + files = append(files, file) + } + cat := io.MultiReader(readers...) + if _, err := io.Copy(w, cat); err != nil { + log.Fatal(err) + } + + for _, x := range files { + x.Close() + } + }) + http.ListenAndServe(":8080", r) }