-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.go
More file actions
37 lines (28 loc) · 853 Bytes
/
Copy pathserver.go
File metadata and controls
37 lines (28 loc) · 853 Bytes
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
package main
import (
"blog/middleware"
"blog/model"
"blog/router"
"net/http"
_ "github.com/go-sql-driver/mysql"
"github.com/jinzhu/gorm"
)
//type Server contains *http.ServeMux and *gorm.DB database instance address.
type Server struct {
mux *http.ServeMux
db *gorm.DB
}
var server Server
//Initiates the server by calling model.DB and router.InitRouter().
func init() {
//server.mux is initiated by router.InitRouter().
//The method to initialize *http.ServeMux instance is in the router package.
server.mux = router.InitRouter()
//Database instance is copied from the inialized db instance from 'model' package.
server.db = model.DB
}
//Initiates middleware by calling middleware.InitiateMiddleware(*gorm.DB, *http.ServeMux).
func (s Server) Server() http.Handler {
m := middleware.InitiateMiddleware(s.db, s.mux)
return m
}