|
@@ -4,38 +4,51 @@ import (
|
|
"html/template"
|
|
"html/template"
|
|
"log"
|
|
"log"
|
|
"net/http"
|
|
"net/http"
|
|
- "os"
|
|
|
|
"path/filepath"
|
|
"path/filepath"
|
|
|
|
|
|
- modules "github.com/help-14/magma/modules"
|
|
|
|
|
|
+ "github.com/help-14/magma/modules"
|
|
)
|
|
)
|
|
|
|
|
|
func main() {
|
|
func main() {
|
|
- tempPath := filepath.Join(".", "temp")
|
|
|
|
- err := os.MkdirAll(tempPath, os.ModePerm)
|
|
|
|
- if err != nil {
|
|
|
|
- log.Fatal(err)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
|
|
+ appConfig := modules.LoadConfig()
|
|
|
|
+
|
|
|
|
+ commonfs := http.FileServer(http.Dir("./common"))
|
|
|
|
+ http.Handle("/common/", http.StripPrefix("/common/", commonfs))
|
|
|
|
|
|
- fs := http.FileServer(http.Dir("./temp"))
|
|
|
|
- http.Handle("/static/", http.StripPrefix("/static/", fs))
|
|
|
|
|
|
+ themePath := "/themes/" + appConfig.Website.Theme + "/"
|
|
|
|
+ themefs := http.FileServer(http.Dir("." + themePath))
|
|
|
|
+ http.Handle("/theme/", http.StripPrefix("/theme/", themefs))
|
|
|
|
|
|
- modules.LoadConfig()
|
|
|
|
|
|
+ http.HandleFunc("/", serveTemplate)
|
|
|
|
+ // tempPath := filepath.Join(".", "temp")
|
|
|
|
+ // err := os.MkdirAll(tempPath, os.ModePerm)
|
|
|
|
+ // if err != nil {
|
|
|
|
+ // log.Fatal(err)
|
|
|
|
+ // return
|
|
|
|
+ // }
|
|
|
|
|
|
log.Println("Listening on :7001 ...")
|
|
log.Println("Listening on :7001 ...")
|
|
- err = http.ListenAndServe(":7001", nil)
|
|
|
|
|
|
+ err := http.ListenAndServe(":7001", nil)
|
|
if err != nil {
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// func TemplatedHandler(response http.ResponseWriter, request *http.Request) {
|
|
|
|
+// tmplt := template.New("hello template")
|
|
|
|
+// tmplt, _ = tmplt.Parse("Top Student: {{.Id}} - {{.Name}}!")
|
|
|
|
+
|
|
|
|
+// p := Student{Id: 1, Name: "Aisha"} //define an instance with required field
|
|
|
|
+
|
|
|
|
+// tmplt.Execute(response, p) //merge template ‘t’ with content of ‘p’
|
|
|
|
+// }
|
|
|
|
+
|
|
func serveTemplate(w http.ResponseWriter, r *http.Request) {
|
|
func serveTemplate(w http.ResponseWriter, r *http.Request) {
|
|
lp := filepath.Join("templates", "layout.html")
|
|
lp := filepath.Join("templates", "layout.html")
|
|
- fp := filepath.Join("templates", filepath.Clean(r.URL.Path))
|
|
|
|
|
|
+ //fp := filepath.Join("templates", filepath.Clean(r.URL.Path))
|
|
|
|
|
|
- tmpl, _ := template.ParseFiles(lp, fp)
|
|
|
|
- tmpl.ExecuteTemplate(w, "layout", nil)
|
|
|
|
|
|
+ tmpl, _ := template.ParseFiles(lp)
|
|
|
|
+ tmpl.Execute(w, nil)
|
|
}
|
|
}
|
|
|
|
|
|
// templ.Execute(file, struct {
|
|
// templ.Execute(file, struct {
|