Skip to content

Commit

Permalink
Upgrade to v5.0.0-rc2
Browse files Browse the repository at this point in the history
  • Loading branch information
System-Glitch committed Jan 12, 2024
1 parent 53ae0a0 commit 62c6e98
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 22 deletions.
11 changes: 6 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ module github.com/go-goyave/websocket-example
go 1.21

require (
github.com/gorilla/websocket v1.5.0
goyave.dev/goyave/v5 v5.0.0-preview4
github.com/gorilla/websocket v1.5.1
goyave.dev/goyave/v5 v5.0.0-rc2
)

require (
github.com/Code-Hex/uniseg v0.2.0 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/samber/lo v1.38.1 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
github.com/samber/lo v1.39.0 // indirect
golang.org/x/exp v0.0.0-20240110193028-0dcbfd608b1e // indirect
golang.org/x/net v0.20.0 // indirect
gorm.io/gorm v1.25.5 // indirect
goyave.dev/copier v0.4.3 // indirect
)
30 changes: 16 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,33 @@ github.com/Code-Hex/uniseg v0.2.0 h1:QB/2UJFvEuRLSZqe+Sb1XQBTWjqGVbZoC6oSWzQRKws
github.com/Code-Hex/uniseg v0.2.0/go.mod h1:/ndS2tP+X1lk2HUOcXWGtVTxVq0lWilwgMa4CbzdRsg=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM=
github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/mattn/go-sqlite3 v1.14.19 h1:fhGleo2h1p8tVChob4I9HpmVFIAkKGpiukdrgQbWfGI=
github.com/mattn/go-sqlite3 v1.14.19/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/samber/lo v1.38.1 h1:j2XEAqXKb09Am4ebOg31SpvzUTTs6EN3VfgeLUhPdXM=
github.com/samber/lo v1.38.1/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
github.com/samber/lo v1.39.0 h1:4gTz1wUhNYLhFSKl6O+8peW0v2F4BCY034GRpU9WnuA=
github.com/samber/lo v1.39.0/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
golang.org/x/exp v0.0.0-20240110193028-0dcbfd608b1e h1:723BNChdd0c2Wk6WOE320qGBiPtYx0F0Bbm1kriShfE=
golang.org/x/exp v0.0.0-20240110193028-0dcbfd608b1e/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/sqlite v1.5.3 h1:7/0dUgX28KAcopdfbRWWl68Rflh6osa4rDh+m51KL2g=
gorm.io/driver/sqlite v1.5.3/go.mod h1:qxAuCol+2r6PannQDpOP1FP6ag3mKi4esLnB/jHed+4=
gorm.io/driver/sqlite v1.5.4 h1:IqXwXi8M/ZlPzH/947tn5uik3aYQslP9BVveoax0nV0=
gorm.io/driver/sqlite v1.5.4/go.mod h1:qxAuCol+2r6PannQDpOP1FP6ag3mKi4esLnB/jHed+4=
gorm.io/gorm v1.25.5 h1:zR9lOiiYf09VNh5Q1gphfyia1JpiClIWG9hQaxB/mls=
gorm.io/gorm v1.25.5/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
goyave.dev/copier v0.4.3 h1:MxX2wBnhQUbv0mHPXEgw/zS4TZMtTVpzj/aYS3h4amk=
goyave.dev/copier v0.4.3/go.mod h1:WJu0Ex81v29f5U0eMWzSNsMTGmuGY6lQ/q5yGlyLDsU=
goyave.dev/goyave/v5 v5.0.0-preview4 h1:56KVaQBZnxYkR6oDzaN8Ce80RNZ8lf4vvx3kTpbHhX8=
goyave.dev/goyave/v5 v5.0.0-preview4/go.mod h1:rd4+UwNWoAKFqnHGhgAStXHvLVvvUBovn2pNlLMxp7U=
goyave.dev/goyave/v5 v5.0.0-rc2 h1:LkpJmcXI+ianjocIZVidU5dMKLAxOrKGr0e4bg6mNU4=
goyave.dev/goyave/v5 v5.0.0-rc2/go.mod h1:BMWwAkDnb63JVCssMkseLn65RQW3qnpd0ogI/4XvPBg=
6 changes: 5 additions & 1 deletion http/route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package route

import (
"github.com/go-goyave/websocket-example/http/controller/chat"
"github.com/go-goyave/websocket-example/service"
"github.com/go-goyave/websocket-example/service/static"
"goyave.dev/goyave/v5"
"goyave.dev/goyave/v5/cors"
"goyave.dev/goyave/v5/log"
Expand All @@ -20,5 +22,7 @@ func Register(server *goyave.Server, router *goyave.Router) {
go hub.Run()

router.Subrouter("/chat").Controller(websocket.New(hub))
router.Static("/", "resources/template", false)

resources := server.Service(service.Static).(*static.Service).FS()
router.Static(resources, "/", false)
}
21 changes: 19 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
package main

import (
"embed"
"fmt"
"os"

"github.com/go-goyave/websocket-example/http/route"
"github.com/go-goyave/websocket-example/service/static"

"goyave.dev/goyave/v5"
"goyave.dev/goyave/v5/util/errors"
"goyave.dev/goyave/v5/util/fsutil"
)

//go:embed resources
var resources embed.FS

func main() {
server, err := goyave.New()

resourcesEmbed := fsutil.NewEmbed(resources)

server, err := goyave.New(goyave.Options{})
if err != nil {
fmt.Println(err.(*errors.Error).String())
fmt.Fprintln(os.Stderr, err.(*errors.Error).String())
os.Exit(1)
}

Expand All @@ -28,6 +37,14 @@ func main() {
s.Logger.Info("Server is shutting down")
})

server.Logger.Info("Registering services")
staticResources, err := resourcesEmbed.Sub("resources/template")
if err != nil {
server.Logger.Error(err)
os.Exit(1)
}
server.RegisterService(static.NewService(staticResources))

server.Logger.Info("Registering routes")
server.RegisterRoutes(route.Register)

Expand Down
6 changes: 6 additions & 0 deletions service/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package service

// Name of the implemented services.
const (
Static = "static"
)
28 changes: 28 additions & 0 deletions service/static/static.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package static

import (
"github.com/go-goyave/websocket-example/service"
"goyave.dev/goyave/v5/util/fsutil"
)

// Service for the static resources.
type Service struct {
fs fsutil.Embed
}

// NewService create a new user Service.
func NewService(fs fsutil.Embed) *Service {
return &Service{
fs: fs,
}
}

// FS returns the static resources filesystem
func (s Service) FS() fsutil.Embed {
return s.fs
}

// Name returns the service name.
func (s *Service) Name() string {
return service.Static
}

0 comments on commit 62c6e98

Please sign in to comment.