modweb/examples/test/hello-world/main.go

47 lines
818 B
Go
Raw Normal View History

2020-11-11 22:48:11 +00:00
package hello_world
2020-11-11 23:51:23 +00:00
import (
"git.ddd.rip/ptrcnull/modweb"
"github.com/gofiber/fiber/v2"
2020-11-16 20:19:37 +00:00
"net/http"
"os"
"path"
2020-11-11 23:51:23 +00:00
)
2020-11-11 22:48:11 +00:00
2020-11-16 20:19:37 +00:00
type Module struct {}
2020-11-11 22:48:11 +00:00
2020-11-16 20:19:37 +00:00
type RealFS struct {
Path string
}
func (fs RealFS) Open(filename string) (http.File, error) {
return os.Open(path.Join(fs.Path, filename))
}
func (m *Module) Init(mm *modweb.ModuleManager) {
mm.RegisterViews(RealFS{Path: "/home/patrycja/Projekty/Go/modweb/examples/test/hello-world/templates"})
2020-11-11 23:51:23 +00:00
app := mm.Fiber()
2020-11-16 20:19:37 +00:00
mm.SetHomepage("index")
2020-11-11 23:51:23 +00:00
app.Get("/", func(ctx *fiber.Ctx) error {
2020-11-16 20:19:37 +00:00
return mm.Render(ctx, "index", fiber.Map{})
2020-11-11 23:51:23 +00:00
})
2020-11-11 22:48:11 +00:00
}
2020-11-16 20:19:37 +00:00
func (m *Module) Name() string {
2020-11-11 22:48:11 +00:00
return "hello-world"
}
2020-11-16 20:19:37 +00:00
func (m *Module) FriendlyName() string {
2020-11-11 22:48:11 +00:00
return "Hello World"
}
2020-11-17 13:52:33 +00:00
func (m *Module) MinAccessLevel() int64 {
2020-11-16 20:19:37 +00:00
return 2136
}
func (m *Module) Hidden() bool {
return false
}