A small project that collects various nice things to get started with Go Web Development.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
go-web-starter-kit/main.go

73 lines
1.5 KiB

package main
import (
"log"
"os"
"os/signal"
"syscall"
"time"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/gofiber/template/html/v2"
"github.com/gofiber/fiber/v2/middleware/session"
_ "github.com/mattn/go-sqlite3"
recov "github.com/gofiber/fiber/v2/middleware/recover"
"MY/webapp/data"
"MY/webapp/config"
"MY/webapp/admin"
"MY/webapp/common"
"MY/webapp/auth"
"MY/webapp/features"
)
func main() {
config.Load("config.json")
log.Printf("ADMIN is %s", config.Settings.Server.Admin)
log.SetFlags(log.LstdFlags | log.Lshortfile)
engine := html.New(config.Settings.Server.Views, ".html")
engine.Reload(true)
app := fiber.New(fiber.Config{
Views: engine,
ViewsLayout: config.Settings.Server.Layouts,
CaseSensitive: true,
StrictRouting: true,
})
app.Use(logger.New())
app.Use(recov.New())
app.Static("/", "./public", fiber.Static{
Compress: false,
CacheDuration: 1 * time.Nanosecond,
})
common.STORE = session.New()
data.Setup(config.Settings.Database.Driver, config.Settings.Database.Url)
auth.Setup(app)
admin.Setup(app)
features.Setup(app)
// this sets up graceful shutdown
go func() {
if err := app.Listen(config.Settings.Server.HostPort); err != nil {
log.Panic(err)
}
}()
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
_ = <-c
log.Println("Shutdown now...")
_ = app.Shutdown()
data.Shutdown()
log.Println("Done.")
}