Skip to content

Instantly share code, notes, and snippets.

@vadviktor
Created January 15, 2025 12:56
Show Gist options
  • Save vadviktor/81db103b0387be8a3b37a35ab9d28959 to your computer and use it in GitHub Desktop.
Save vadviktor/81db103b0387be8a3b37a35ab9d28959 to your computer and use it in GitHub Desktop.
Embedding a Blazor Webassembly SPA in Go with Echo
package main
import (
"embed"
"fmt"
"io/fs"
"net/http"
"github.com/labstack/echo/v4"
)
//go:embed wasm/wwwroot/*
var content embed.FS
func main() {
e := echo.New()
staticFiles, err := fs.Sub(content, "wasm/wwwroot")
if err != nil {
fmt.Println("Error accessing embedded content:", err)
return
}
fs.WalkDir(staticFiles, ".", func(path string, d fs.DirEntry, err error) error {
if err != nil {
fmt.Println("Error walking directory:", err)
return err
}
fmt.Println("Embedded file:", path)
return nil
})
e.GET("/api/hello", func(c echo.Context) error {
return c.String(http.StatusOK, "Hello, World!")
})
e.StaticFS("/", staticFiles)
e.Logger.Fatal(e.Start("localhost:5000"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment