Files
sonr/cmd/motr/main.go
T

47 lines
824 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"
2024-10-11 16:47:52 -04:00
"github.com/onsonr/sonr/internal/dwn"
dwngen "github.com/onsonr/sonr/internal/dwn/gen"
"github.com/onsonr/sonr/pkg/workers/routes"
2024-09-18 02:22:17 -04:00
)
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()
2024-10-11 16:47:52 -04:00
e.Use(ctx.SessionMiddleware)
routes.RegisterClientAPI(e)
2024-10-11 16:47:52 -04:00
routes.RegisterClientViews(e)
dwn.Serve(e)
}
func loadDwnConfig() error {
// Read dwn.json config
dwnBz, err := os.ReadFile("dwn.json")
if err != nil {
return err
}
dwnConfig := &dwngen.Config{}
err = json.Unmarshal(dwnBz, dwnConfig)
if err != nil {
return err
}
config = dwnConfig
return nil
2024-09-18 02:22:17 -04:00
}