-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (45 loc) · 1.1 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
package main
import (
"github.com/gin-gonic/gin"
"net/http"
"time"
"github.com/tkanos/gonfig"
"./config"
"./middleware"
"./controllers"
"./services"
)
func main() {
configuration := config.Config{}
err := gonfig.GetConf("./config/development-config.json", &configuration)
service, err := services.NewService(
services.WithGorm(configuration.Dialect, configuration.GetConnectionInfo()),
services.WithUser(),
services.WithChat(),
)
uc := controllers.NewUserController(service.User)
cc := controllers.NewChatController(service.Chat)
if err != nil {
panic(err)
}
defer service.Close()
fs := http.FileServer(http.Dir("../public"))
http.Handle("/", fs)
r := gin.Default()
private := r.Group("users")
r.POST("/auth", uc.SignIn)
r.POST("/users", uc.Create)
r.GET("/users", uc.All)
r.GET("/ws", cc.HandleConnection)
private.Use(middleware.IsAuthenticated())
private.GET("/me", uc.Me)
s := &http.Server{
Addr: ":8000",
Handler: r,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20,
}
go cc.HandleMessages()
s.ListenAndServe()
}