Whats up all people.
It is a easy net utility witch makes use of embedded fs for storing css and js information
package deal primary
import (
"embed"
"io/fs"
"web/http"
)
//go:embed static/*
var StaticFiles embed.FS
sort StaticPath struct {
StaticP embed.FS
}
func (s StaticPath) ServeHTTP(w http.ResponseWriter, req *http.Request) {
publicFS, _ := fs.Sub(s.StaticP, "static")
http.FileServer(http.FS(publicFS)).ServeHTTP(w, req)
}
func NewRouter() *http.ServeMux {
r := http.NewServeMux()
r.Deal with("https://discussion board.golangbridge.org/", StaticPath{
StaticP: StaticFiles,
})
return r
}
func primary() {
srv := &http.Server{
Addr: "localhost:3000",
Handler: NewRouter(),
}
_ = srv.ListenAndServe()
}
listing struccture:
├── go.mod
├── go.sum
├── primary.go
└── static
├── index.html
└── fashion.css
2 directories, 5 information
apache 2 configuration is: (cat /and many others/apache2/conf-enabled/app1.conf)
<VirtualHost *:80>
ProxyPass /app1 http://localhost:3000/
ProxyPassReverse /app1 http://localhost:3000/
</VirtualHost>
Html web page served fantastic however css and js information in static folder not.
I shouldn’t have a clue the place the issue is. Might someone assist me?
I don’t know something about embedded information or apache, however I do know that checking errors as a substitute of ignoring them normally provides a clue.
1 Like

