51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"embed"
|
|
"git.keks.cloud/kekskurse/go-sample-webpage/pkg/dashboard"
|
|
"git.keks.cloud/kekskurse/go-sample-webpage/pkg/sample"
|
|
"git.keks.cloud/kekskurse/go-sample-webpage/pkg/user"
|
|
"git.keks.cloud/kekskurse/go-sample-webpage/pkg/webpage"
|
|
"github.com/go-chi/chi/v5"
|
|
"github.com/go-chi/jwtauth/v5"
|
|
"github.com/jmoiron/sqlx"
|
|
gomail "gopkg.in/mail.v2"
|
|
"net/http"
|
|
)
|
|
|
|
// content holds our static web server content.
|
|
//go:embed static/* templates/*
|
|
var webserver embed.FS
|
|
|
|
//go:embed database/migrations/*.sql
|
|
var migrationFS embed.FS
|
|
|
|
func main() {
|
|
tokenAuth := jwtauth.New("HS256", []byte("secret"), nil)
|
|
config := webpage.WebPageConfig{
|
|
Templates: webserver,
|
|
Static: webserver,
|
|
Migrations: migrationFS,
|
|
Token: tokenAuth,
|
|
Bootstrap: func(router chi.Router, template func(http.Handler) http.Handler) {
|
|
db, err := sqlx.Open("mysql", "root:test@tcp(localhost:3306)/test?multiStatements=true")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
uc := user.NewUserClientSql(db)
|
|
|
|
d := gomail.NewDialer("localhost", 1025, "from@gmail.com", "email_password")
|
|
d.TLSConfig = &tls.Config{InsecureSkipVerify: true}
|
|
|
|
userconfig := user.NewUserConfig()
|
|
|
|
sample.Register(router)
|
|
user.Register(router, template, tokenAuth, uc, d, userconfig)
|
|
|
|
dashboard.Register(router, template)
|
|
},
|
|
}
|
|
|
|
webpage.RunWebApp(config)
|
|
}
|