1
0
mirror of https://github.com/taigrr/catserver synced 2025-01-18 04:03:20 -08:00

added test files and initial static version

This commit is contained in:
Tai Groot 2020-06-21 17:59:14 -07:00
parent 2a3496bac3
commit 796209b133
Signed by: taigrr
GPG Key ID: D00C269A87614812
4 changed files with 51 additions and 2 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
catserver

1
css/main.css Normal file
View File

@ -0,0 +1 @@
ade

1
css/test.css Normal file
View File

@ -0,0 +1 @@
ade

50
main.go
View File

@ -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)
}