project struct is ok
This commit is contained in:
parent
da3b3ea0dc
commit
2bbab83d99
37 changed files with 57 additions and 38 deletions
Before Width: | Height: | Size: 126 KiB After Width: | Height: | Size: 126 KiB |
|
@ -2,9 +2,13 @@ module github.com/help-14/magma
|
|||
|
||||
go 1.18
|
||||
|
||||
require gopkg.in/yaml.v2 v2.4.0
|
||||
require (
|
||||
github.com/tdewolff/minify v2.3.6+incompatible
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/tdewolff/minify/v2 v2.10.0 // indirect
|
||||
github.com/tdewolff/parse v2.3.4+incompatible // indirect
|
||||
github.com/tdewolff/parse/v2 v2.5.27 // indirect
|
||||
)
|
||||
|
|
|
@ -4,8 +4,12 @@ github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25Kn
|
|||
github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU=
|
||||
github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2/go.mod h1:0KeJpeMD6o+O4hW7qJOT7vyQPKrWmj26uf5wMc/IiIs=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/tdewolff/minify v2.3.6+incompatible h1:2hw5/9ZvxhWLvBUnHE06gElGYz+Jv9R4Eys0XUzItYo=
|
||||
github.com/tdewolff/minify v2.3.6+incompatible/go.mod h1:9Ov578KJUmAWpS6NeZwRZyT56Uf6o3Mcz9CEsg8USYs=
|
||||
github.com/tdewolff/minify/v2 v2.10.0 h1:ovVAHUcjfGrBDf1EIvsodRUVJiZK/28mMose08B7k14=
|
||||
github.com/tdewolff/minify/v2 v2.10.0/go.mod h1:6XAjcHM46pFcRE0eztigFPm0Q+Cxsw8YhEWT+rDkcZM=
|
||||
github.com/tdewolff/parse v2.3.4+incompatible h1:x05/cnGwIMf4ceLuDMBOdQ1qGniMoxpP46ghf0Qzh38=
|
||||
github.com/tdewolff/parse v2.3.4+incompatible/go.mod h1:8oBwCsVmUkgHO8M5iCzSIDtpzXOT0WXX9cWhz+bIzJQ=
|
||||
github.com/tdewolff/parse/v2 v2.5.27 h1:PL3LzzXaOpmdrknnOlIeO2muIBHAwiKp6TxN1RbU5gI=
|
||||
github.com/tdewolff/parse/v2 v2.5.27/go.mod h1:WzaJpRSbwq++EIQHYIRTpbYKNA3gn9it1Ik++q4zyho=
|
||||
github.com/tdewolff/test v1.0.6/go.mod h1:6DAvZliBAAnD7rhVgwaM7DE5/d9NMOAJ09SqYqeK4QE=
|
||||
|
|
43
src/main.go
43
src/main.go
|
@ -4,38 +4,51 @@ import (
|
|||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
modules "github.com/help-14/magma/modules"
|
||||
"github.com/help-14/magma/modules"
|
||||
)
|
||||
|
||||
func main() {
|
||||
tempPath := filepath.Join(".", "temp")
|
||||
err := os.MkdirAll(tempPath, os.ModePerm)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return
|
||||
}
|
||||
appConfig := modules.LoadConfig()
|
||||
|
||||
fs := http.FileServer(http.Dir("./temp"))
|
||||
http.Handle("/static/", http.StripPrefix("/static/", fs))
|
||||
commonfs := http.FileServer(http.Dir("./common"))
|
||||
http.Handle("/common/", http.StripPrefix("/common/", commonfs))
|
||||
|
||||
modules.LoadConfig()
|
||||
themePath := "/themes/" + appConfig.Website.Theme + "/"
|
||||
themefs := http.FileServer(http.Dir("." + themePath))
|
||||
http.Handle("/theme/", http.StripPrefix("/theme/", themefs))
|
||||
|
||||
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 ...")
|
||||
err = http.ListenAndServe(":7001", nil)
|
||||
err := http.ListenAndServe(":7001", nil)
|
||||
if err != nil {
|
||||
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) {
|
||||
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 {
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package modules
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"regexp"
|
||||
|
||||
"github.com/tdewolff/minify"
|
||||
|
@ -23,24 +21,24 @@ func Compile() {
|
|||
m.AddFuncRegexp(regexp.MustCompile("[/+]json$"), json.Minify)
|
||||
m.AddFuncRegexp(regexp.MustCompile("[/+]xml$"), xml.Minify)
|
||||
|
||||
items, _ := ioutil.ReadDir("./private")
|
||||
for _, item := range items {
|
||||
if item.IsDir() {
|
||||
subitems, _ := ioutil.ReadDir(item.Name())
|
||||
for _, subitem := range subitems {
|
||||
if !subitem.IsDir() {
|
||||
// handle file there
|
||||
fmt.Println(item.Name() + "/" + subitem.Name())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// handle file there
|
||||
fmt.Println(item.Name())
|
||||
}
|
||||
}
|
||||
// items, _ := ioutil.ReadDir("./private")
|
||||
// for _, item := range items {
|
||||
// if item.IsDir() {
|
||||
// subitems, _ := ioutil.ReadDir(item.Name())
|
||||
// for _, subitem := range subitems {
|
||||
// if !subitem.IsDir() {
|
||||
// // handle file there
|
||||
// fmt.Println(item.Name() + "/" + subitem.Name())
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// // handle file there
|
||||
// fmt.Println(item.Name())
|
||||
// }
|
||||
// }
|
||||
|
||||
s, err = m.String(mediatype, s)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// s, err = m.String(mediatype, s)
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ func LoadConfig() Config {
|
|||
Addons: []string{},
|
||||
}
|
||||
|
||||
yamlFile, err := ioutil.ReadFile("./public/config.yaml")
|
||||
yamlFile, err := ioutil.ReadFile("./common/config.yaml")
|
||||
if err != nil {
|
||||
fmt.Printf("Error reading YAML file: %s\n", err)
|
||||
return defaultConfig
|
||||
|
|
Before Width: | Height: | Size: 51 KiB After Width: | Height: | Size: 51 KiB |
Loading…
Add table
Reference in a new issue