Files
sonr/internal/dwn/wasm/main.go
T

49 lines
894 B
Go
Raw Normal View History

2024-09-18 02:22:17 -04:00
//go:build js && wasm
// +build js,wasm
package main
import (
2024-10-11 16:47:52 -04:00
"encoding/json"
"os"
2024-09-18 02:22:17 -04:00
"github.com/labstack/echo/v4"
"github.com/onsonr/sonr/internal/ctx"
"github.com/onsonr/sonr/internal/dwn/fetch"
2024-10-11 16:47:52 -04:00
dwngen "github.com/onsonr/sonr/internal/dwn/gen"
"github.com/onsonr/sonr/pkg/workers/routes"
2024-09-18 02:22:17 -04:00
)
const FileNameConfigJSON = "dwn.json"
2024-10-11 16:47:52 -04:00
var config *dwngen.Config
2024-09-18 02:22:17 -04:00
func main() {
2024-10-11 16:47:52 -04:00
// Load dwn config
if err := loadDwnConfig(); err != nil {
panic(err)
}
// Setup HTTP server
2024-09-18 02:22:17 -04:00
e := echo.New()
e.Use(ctx.DWNSessionMiddleware(config))
routes.RegisterWebNodeAPI(e)
routes.RegisterWebNodeViews(e)
fetch.Serve(e)
2024-10-11 16:47:52 -04:00
}
func loadDwnConfig() error {
// Read dwn.json config
dwnBz, err := os.ReadFile(FileNameConfigJSON)
2024-10-11 16:47:52 -04:00
if err != nil {
return err
}
dwnConfig := new(dwngen.Config)
2024-10-11 16:47:52 -04:00
err = json.Unmarshal(dwnBz, dwnConfig)
if err != nil {
return err
}
config = dwnConfig
return nil
2024-09-18 02:22:17 -04:00
}