This commit is contained in:
27
main.go
Normal file
27
main.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"io/fs"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
//go:embed public/*
|
||||
var publicFS embed.FS
|
||||
|
||||
func main() {
|
||||
// Получаем подпапку 'public' из embed.FS
|
||||
pub, err := fs.Sub(publicFS, "public")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Создаем файловый сервер с корнем в подпапке public
|
||||
fileServer := http.FileServer(http.FS(pub))
|
||||
|
||||
http.Handle("/", fileServer)
|
||||
|
||||
log.Println("Server starting on :8080")
|
||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||
}
|
Reference in New Issue
Block a user