Created
January 15, 2025 12:56
-
-
Save vadviktor/81db103b0387be8a3b37a35ab9d28959 to your computer and use it in GitHub Desktop.
Embedding a Blazor Webassembly SPA in Go with Echo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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