-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
69 lines (52 loc) · 2.06 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
package main
import (
"log"
"net/http"
"github.com/gorilla/mux"
"github.com/ligenhw/goshare/configration"
"github.com/ligenhw/goshare/handler"
"github.com/ligenhw/goshare/handler/middleware"
"github.com/ligenhw/goshare/mongo"
"github.com/ligenhw/goshare/session"
"github.com/ligenhw/goshare/version"
_ "github.com/ligenhw/goshare/session/redis"
)
var (
globalSession *session.Manager
)
func init() {
log.SetFlags(log.Flags() | log.Llongfile)
globalSession, _ = session.NewManager("redis", configration.Conf.SavePath)
go globalSession.GC()
}
var (
u = middleware.CheckUser
)
func main() {
p("Go share", version.Version, "started at", configration.Conf.Address)
r := mux.NewRouter()
r.Use(middleware.LoggingMiddleware)
r.HandleFunc("/api/user", u(handler.GetUser)).Methods("GET")
r.HandleFunc("/api/user", handler.CreateUser).Methods("POST")
r.HandleFunc("/api/login", handler.Login).Methods("POST")
r.HandleFunc("/api/logout", handler.Logout).Methods("POST")
r.HandleFunc("/api/article", handler.GetArticles).Methods("GET")
r.HandleFunc("/api/article", u(handler.CreateArticle)).Methods("POST")
r.HandleFunc("/api/article", u(handler.UpdateArticle)).Methods("PUT")
r.HandleFunc("/api/article/{id}", handler.GetArticleByID).Methods("GET")
r.HandleFunc("/api/article/{id}", u(handler.DeleteArticle)).Methods("DELETE")
r.HandleFunc("/api/archives", handler.GetArchives).Methods("GET")
r.HandleFunc("/api/comment/{blogId}", handler.GetComment).Methods("GET")
r.HandleFunc("/api/comment", u(handler.CreateComment)).Methods("POST")
r.HandleFunc("/api/tag", handler.TagHandler)
r.HandleFunc("/api/ghlogin", handler.GhLogin).Methods("POST")
r.HandleFunc("/api/qqlogin", handler.QqLogin).Methods("POST")
r.HandleFunc("/api/alipaylogin", handler.AlipayLogin).Methods("POST")
r.HandleFunc("/api/link", mongo.GetLinks).Methods("GET")
r.HandleFunc("/api/book", mongo.GetBooks).Methods("GET")
r.HandleFunc("/api/project", mongo.GetProjects).Methods("GET")
http.Handle("/", r)
if err := http.ListenAndServe(configration.Conf.Address, nil); err != nil {
panic(err)
}
}