-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
56 lines (51 loc) · 1.11 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
package main
import (
"github.com/gin-contrib/cors"
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/redis"
"strings"
"time"
"wehub/internal/web"
"wehub/internal/web/middleware"
"github.com/gin-gonic/gin"
)
func main() {
db := web.InitDb()
server := gin.Default()
server.Use(cors.New(cors.Config{
AllowHeaders: []string{"Content-Type"},
AllowCredentials: true,
AllowOriginFunc: func(origin string) bool {
if strings.Contains(origin, "localhost") {
return true
}
return origin == "https://tinywaves.com"
},
MaxAge: 12 * time.Hour,
}))
store, err := redis.NewStore(
16,
"tcp",
"localhost:16379",
"",
[]byte("3D2hLRGG3FttMZLUCg31KhP9hL2R6u6Q"),
[]byte("CwwUsFPRppmsvsU7ju7JRjZW4P26cpks"),
)
if err != nil {
panic(err)
}
server.Use(sessions.Sessions("wehub_ssid", store))
server.Use(
middleware.
InitSignInCheckMiddlewareBuilder().
IgnorePath("/v1/api/user/sign-up").
IgnorePath("/v1/api/user/sign-in").
Build(),
)
rootRouter := server.Group("/v1/api")
web.InitUser(rootRouter, db)
err = server.Run(":8080")
if err != nil {
return
}
}