2018-01-26 08:43:53 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net/http"
|
2018-01-29 16:52:59 +01:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/gorilla/securecookie"
|
2018-01-26 08:43:53 +01:00
|
|
|
|
2018-01-26 14:49:03 +01:00
|
|
|
"git.klink.asia/paul/certman/services"
|
2018-01-26 08:43:53 +01:00
|
|
|
|
|
|
|
"git.klink.asia/paul/certman/router"
|
|
|
|
"git.klink.asia/paul/certman/views"
|
|
|
|
|
2018-01-29 16:52:59 +01:00
|
|
|
// import sqlite3 driver
|
2018-01-26 08:43:53 +01:00
|
|
|
_ "github.com/mattn/go-sqlite3"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2018-01-29 16:52:59 +01:00
|
|
|
c := services.Config{
|
|
|
|
DB: &services.DBConfig{
|
|
|
|
Type: "sqlite3",
|
|
|
|
DSN: "db.sqlite3",
|
|
|
|
Log: true,
|
|
|
|
},
|
|
|
|
Sessions: &services.SessionsConfig{
|
|
|
|
SessionName: "_session",
|
|
|
|
CookieKey: string(securecookie.GenerateRandomKey(32)),
|
|
|
|
HttpOnly: true,
|
|
|
|
Lifetime: 24 * time.Hour,
|
|
|
|
},
|
|
|
|
Email: &services.EmailConfig{
|
2018-02-01 03:30:00 +01:00
|
|
|
SMTPEnabled: false,
|
2018-01-29 16:52:59 +01:00
|
|
|
SMTPServer: "example.com",
|
|
|
|
SMTPPort: 25,
|
|
|
|
SMTPUsername: "test",
|
2018-01-29 20:55:25 +01:00
|
|
|
SMTPPassword: "password",
|
|
|
|
SMTPTimeout: 5 * time.Second,
|
2018-01-29 16:52:59 +01:00
|
|
|
From: "Mailtest <test@example.com>",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
serviceProvider := services.NewProvider(&c)
|
|
|
|
|
|
|
|
// Start the mail daemon, which re-uses connections to send mails to the
|
|
|
|
// SMTP server
|
|
|
|
go serviceProvider.Email.Daemon()
|
2018-01-29 09:18:19 +01:00
|
|
|
|
2018-01-26 08:43:53 +01:00
|
|
|
// load and parse template files
|
|
|
|
views.LoadTemplates()
|
|
|
|
|
2018-01-29 16:52:59 +01:00
|
|
|
mux := router.HandleRoutes(serviceProvider)
|
2018-01-26 08:43:53 +01:00
|
|
|
|
2018-01-26 14:49:03 +01:00
|
|
|
err := http.ListenAndServe(":8000", mux)
|
2018-01-26 08:43:53 +01:00
|
|
|
log.Fatalf(err.Error())
|
|
|
|
}
|