go-sample-webpage/main.go

52 lines
1.3 KiB
Go
Raw Normal View History

2021-11-03 01:10:36 +00:00
package main
import (
2021-11-22 22:46:01 +00:00
"crypto/tls"
2021-11-03 01:10:36 +00:00
"embed"
2021-11-25 00:32:48 +00:00
"git.keks.cloud/kekskurse/go-sample-webpage/pkg/dashboard"
2021-11-09 11:34:25 +00:00
"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"
2021-11-22 22:11:37 +00:00
"github.com/go-chi/chi/v5"
"github.com/go-chi/jwtauth/v5"
2021-11-23 20:32:55 +00:00
"github.com/jmoiron/sqlx"
2021-11-22 22:46:01 +00:00
gomail "gopkg.in/mail.v2"
2021-11-24 02:27:07 +00:00
"net/http"
2021-11-03 01:10:36 +00:00
)
// content holds our static web server content.
//go:embed static/* templates/*
var webserver embed.FS
2021-11-08 01:25:36 +00:00
//go:embed database/migrations/*.sql
var migrationFS embed.FS
2021-11-03 01:10:36 +00:00
func main() {
2021-11-25 00:32:48 +00:00
tokenAuth := jwtauth.New("HS256", []byte("secret"), nil)
2021-11-08 02:33:36 +00:00
config := webpage.WebPageConfig{
Templates: webserver,
Static: webserver,
Migrations: migrationFS,
2021-11-25 00:32:48 +00:00
Token: tokenAuth,
2021-11-24 02:27:07 +00:00
Bootstrap: func(router chi.Router, template func(http.Handler) http.Handler) {
2021-11-23 20:32:55 +00:00
db, err := sqlx.Open("mysql", "root:test@tcp(localhost:3306)/test?multiStatements=true")
if err != nil {
panic(err)
}
uc := user.NewUserClientSql(db)
2021-11-22 22:46:01 +00:00
d := gomail.NewDialer("localhost", 1025, "from@gmail.com", "email_password")
d.TLSConfig = &tls.Config{InsecureSkipVerify: true}
2021-11-22 22:11:37 +00:00
2021-11-23 19:21:43 +00:00
userconfig := user.NewUserConfig()
2021-11-22 22:11:37 +00:00
sample.Register(router)
2021-11-24 02:27:07 +00:00
user.Register(router, template, tokenAuth, uc, d, userconfig)
2021-11-25 00:32:48 +00:00
dashboard.Register(router, template)
2021-11-08 01:25:36 +00:00
},
}
2021-11-08 02:33:36 +00:00
webpage.RunWebApp(config)
2021-11-08 01:25:36 +00:00
}