Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions backend-entry.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Our empty version of the httpServer for usage with the wasm target
// this way we will not include any of the related code
//go:build !wasm
//go:build !js

package main

import (
"github.com/maxence-charriere/go-app/v9/pkg/app"
"go-nats-app/back"

"github.com/maxence-charriere/go-app/v9/pkg/app"
)

type empty struct{ app.Compo }
Expand Down
2 changes: 1 addition & 1 deletion frontent-wasm.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Our empty version of the httpServer for usage with the wasm target
// this way we will not include any of the related code
//go:build wasm
//go:build js

package main

Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module go-nats-app

go 1.19
go 1.18

require (
github.com/go-chi/chi/v5 v5.0.7
Expand All @@ -25,3 +25,5 @@ require (
golang.org/x/sys v0.2.0 // indirect
golang.org/x/time v0.2.0 // indirect
)

replace github.com/maxence-charriere/go-app/v9 => github.com/nevkontakte/go-app/v9 v9.0.0-20230311130033-7d595cf8ec05
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ github.com/magefile/mage v1.14.0 h1:6QDX3g6z1YvJ4olPhT1wksUcSa/V0a1B+pJb73fBjyo=
github.com/magefile/mage v1.14.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/maxence-charriere/go-app/v9 v9.6.7 h1:t+wofnLjVsptBB7MNevsFymMYaMIX2hGjLdWgsIFgq4=
github.com/maxence-charriere/go-app/v9 v9.6.7/go.mod h1:UlniES44R5JoD4HsjMNrAqWXSzyw0smM0Ox+QwnO/IE=
github.com/minio/highwayhash v1.0.2 h1:Aak5U0nElisjDCfPSG79Tgzkn2gl66NxOMspRrKnA/g=
github.com/minio/highwayhash v1.0.2/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
Expand All @@ -63,6 +61,8 @@ github.com/nats-io/nkeys v0.3.0 h1:cgM5tL53EvYRU+2YLXIK0G2mJtK12Ft9oeooSZMA2G8=
github.com/nats-io/nkeys v0.3.0/go.mod h1:gvUNGjVcM2IPr5rCsRsC6Wb3Hr2CQAm08dsxtV6A5y4=
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
github.com/nevkontakte/go-app/v9 v9.0.0-20230311130033-7d595cf8ec05 h1:D8IcaQrdz1vBUUM/tWe+aUtY/oq9Nd8k9bSGNWt4iuA=
github.com/nevkontakte/go-app/v9 v9.0.0-20230311130033-7d595cf8ec05/go.mod h1:UlniES44R5JoD4HsjMNrAqWXSzyw0smM0Ox+QwnO/IE=
github.com/o1egl/govatar v0.4.1 h1:RRzAxm52WpZMSEoWgAXrTcXWKhIUPpgpI54KP+UI0Ew=
github.com/o1egl/govatar v0.4.1/go.mod h1:cSBJjpgYiKmQ8E+C4zNBcsbuDwy9UH4HS8BwE4m6JmQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
15 changes: 8 additions & 7 deletions magefiles/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ package main

import (
"fmt"
"runtime"

"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
"github.com/magefile/mage/target"
"runtime"
)

var appExecutable = "bin/go-nats-app"
var appDir = "."

const goCompiler = "go"
const gopherjsCompiler = "gopherjs"

var appGlobs = []string{
"magefiles/magefile.go",
Expand All @@ -38,21 +40,20 @@ func buildApp() error {
return sh.RunV(goCompiler, "build", "-o", appExecutable, appDir)
}

func BuildWasm() error {
changes, err := target.Glob("web/app.wasm", appGlobs...)
func BuildFrontend() error {
changes, err := target.Glob("web/app.js", appGlobs...)
if err != nil {
return err
}
if !changes {
return nil
}
fmt.Println("> Building WASM...")
return sh.RunWithV(map[string]string{"GOOS": "js", "GOARCH": "wasm"}, goCompiler, "build", "-o",
"web/app.wasm", appDir)
fmt.Println("> Building Frontend...")
return sh.RunV(gopherjsCompiler, "build", "-m", "-o", "web/app.js", appDir)
}

func Build() error {
mg.Deps(BuildWasm)
mg.Deps(BuildFrontend)
return buildApp()
}

Expand Down
9 changes: 5 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package main

import (
"github.com/maxence-charriere/go-app/v9/pkg/app"
"math/rand"
"time"

"github.com/maxence-charriere/go-app/v9/pkg/app"
)

func main() {
rand.Seed(time.Now().UnixNano()) // needs to be better for a real app

// check the system for int64 fitting into int (so we can convert int64 to int safely)
if uint64(^uint(0)) < ^uint64(0) {
panic("int does not fit int64")
}
// if uint64(^uint(0)) < ^uint64(0) {
// panic("int does not fit int64")
// }

// This is behind a WASM build tag so the business logic of the UI does not increase
// the size of our server executable.
Expand Down
162 changes: 162 additions & 0 deletions web/app.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions web/app.js.map

Large diffs are not rendered by default.

Binary file removed web/app.wasm
Binary file not shown.