Server static files
This commit is contained in:
parent
2ba0a0024e
commit
73a1c8bc02
7 changed files with 52 additions and 14 deletions
|
|
@ -15,5 +15,21 @@ func main() {
|
|||
notesRouter := views.GetRoutes("/notes")
|
||||
|
||||
router.Handle("/notes/", http.StripPrefix("/notes", notesRouter))
|
||||
router.Handle(
|
||||
conf.Conf.Static.Root,
|
||||
logger(
|
||||
http.StripPrefix(
|
||||
"/static",
|
||||
http.FileServer(http.Dir(conf.Conf.Static.Dir)),
|
||||
),
|
||||
),
|
||||
)
|
||||
log.Fatal(http.ListenAndServe(":8080", router))
|
||||
}
|
||||
|
||||
func logger(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
log.Print(r.URL.Path)
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
10
conf.toml
10
conf.toml
|
|
@ -1,4 +1,10 @@
|
|||
extension = "md"
|
||||
notesdir = "saved_notes"
|
||||
templatesdir = "templates"
|
||||
basetemplate = "base.tmpl.html"
|
||||
|
||||
[templates]
|
||||
dir = "templates"
|
||||
base = "base.tmpl.html"
|
||||
|
||||
[static]
|
||||
dir = "/home/max/src/gonotes/static"
|
||||
root = "/static/"
|
||||
|
|
|
|||
7
go.mod
7
go.mod
|
|
@ -4,6 +4,7 @@ go 1.23.5
|
|||
|
||||
require github.com/yuin/goldmark v1.7.8
|
||||
|
||||
require github.com/pelletier/go-toml v1.9.5
|
||||
|
||||
require gitea.gwairfelin.com/max/gispatcho v0.1.1
|
||||
require (
|
||||
gitea.gwairfelin.com/max/gispatcho v0.1.1
|
||||
github.com/pelletier/go-toml/v2 v2.2.3
|
||||
)
|
||||
|
|
|
|||
12
go.sum
12
go.sum
|
|
@ -1,6 +1,14 @@
|
|||
gitea.gwairfelin.com/max/gispatcho v0.1.1 h1:8Zv6UH046mSSLdf0PqpNRK6DACuWJfgBSUiWhMW0sMY=
|
||||
gitea.gwairfelin.com/max/gispatcho v0.1.1/go.mod h1:TRhxU+uNv+nIcFIxy2jl30DPbcM5Yib0S/cpLXws5iM=
|
||||
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
|
||||
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
|
||||
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/yuin/goldmark v1.7.8 h1:iERMLn0/QJeHFhxSt3p6PeN9mGnvIKSpG9YYorDMnic=
|
||||
github.com/yuin/goldmark v1.7.8/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
|
|
|||
|
|
@ -4,14 +4,20 @@ import (
|
|||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/pelletier/go-toml"
|
||||
"github.com/pelletier/go-toml/v2"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Extension string
|
||||
NotesDir string
|
||||
TemplatesDir string
|
||||
BaseTemplate string
|
||||
Extension string
|
||||
NotesDir string
|
||||
Templates struct {
|
||||
Dir string
|
||||
Base string
|
||||
}
|
||||
Static struct {
|
||||
Dir string
|
||||
Root string
|
||||
}
|
||||
}
|
||||
|
||||
var Conf Config
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ type Ctx map[string]any
|
|||
|
||||
func RenderTemplate(w http.ResponseWriter, tmpl string, context any) error {
|
||||
files := []string{
|
||||
filepath.Join(conf.Conf.TemplatesDir, conf.Conf.BaseTemplate),
|
||||
filepath.Join(conf.Conf.TemplatesDir, tmpl),
|
||||
filepath.Join(conf.Conf.Templates.Dir, conf.Conf.Templates.Base),
|
||||
filepath.Join(conf.Conf.Templates.Dir, tmpl),
|
||||
}
|
||||
|
||||
for _, f := range files {
|
||||
|
|
|
|||
1
static/.gitignore
vendored
Normal file
1
static/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
*
|
||||
Loading…
Add table
Reference in a new issue