-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
77 lines (61 loc) · 1.91 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
// import "github.com/dfang/qor-demo/config/bindatafs"
import (
"fmt"
"net/http"
"github.com/jinzhu/gorm"
"github.com/qor/auth"
"github.com/qor/auth/auth_identity"
// "github.com/qor/auth/providers/password"
"github.com/qor/auth_themes/clean"
"github.com/qor/session/manager"
"github.com/qor/mailer"
"github.com/qor/mailer/logger"
// "github.com/qor/render"
"github.com/qor/redirect_back"
_ "github.com/mattn/go-sqlite3"
)
var (
Mailer *mailer.Mailer
RedirectBack = redirect_back.New(&redirect_back.Config{
SessionManager: manager.SessionManager,
IgnoredPrefixes: []string{"/auth"},
})
)
var (
// Initialize gorm DB
gormDB, _ = gorm.Open("sqlite3", "sample.db")
// Initialize Auth with configuration
Auth = clean.New(&auth.Config{
DB: gormDB,
// NO NEED TO CONFIG RENDER, AS IT'S CONFIGED IN CLEAN THEME
// Render: render.New(&render.Config{AssetFileSystem: bindatafs.AssetFS.NameSpace("auth")}),
Mailer: Mailer,
UserModel: User{},
Redirector: auth.Redirector{RedirectBack: RedirectBack},
})
)
type User struct {
Name string
}
func init() {
// Migrate AuthIdentity model, AuthIdentity will be used to save auth info, like username/password, oauth token, you could change that.
gormDB.AutoMigrate(&auth_identity.AuthIdentity{})
gormDB.AutoMigrate(&User{})
// Register Auth providers, Allow use username/password
// NO NEED TO REGISTER, AS IT'S REGISTERED IN CLEAN THEME
// Auth.RegisterProvider(password.New(&password.Config{}))
Mailer = mailer.New(&mailer.Config{
Sender: logger.New(&logger.Config{}),
})
}
func main() {
mux := http.NewServeMux()
// Mount Auth to Router
mux.Handle("/auth/", Auth.NewServeMux())
mux.HandleFunc("/", IndexHandler)
http.ListenAndServe(":9000", manager.SessionManager.Middleware(mux))
}
func IndexHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "/auth/login")
}