-
Notifications
You must be signed in to change notification settings - Fork 13
/
server.go
57 lines (51 loc) · 2.09 KB
/
server.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
package main
import (
"github.com/gin-gonic/gin"
"github.com/coretrix/hitrix"
"github.com/coretrix/hitrix/example/entity"
"github.com/coretrix/hitrix/example/graph"
"github.com/coretrix/hitrix/example/graph/generated"
model "github.com/coretrix/hitrix/example/model/socket"
exampleOSS "github.com/coretrix/hitrix/example/oss"
exampleMiddleware "github.com/coretrix/hitrix/example/rest/middleware"
"github.com/coretrix/hitrix/pkg/middleware"
"github.com/coretrix/hitrix/service/component/app"
"github.com/coretrix/hitrix/service/component/oss"
"github.com/coretrix/hitrix/service/component/password"
"github.com/coretrix/hitrix/service/component/socket"
"github.com/coretrix/hitrix/service/registry"
)
var eventHandlersMap = socket.NamespaceEventHandlerMap{
model.DefaultWebsocketNamespace: &socket.EventHandlers{
RegisterHandler: model.RegisterSocketHandler,
UnregisterHandler: model.UnRegisterSocketHandler,
},
}
func main() {
s, deferFunc := hitrix.New(
"my-app", "secret",
).RegisterDIGlobalService(
registry.ServiceProviderErrorLogger(),
registry.ServiceProviderConfigDirectory("config"),
registry.ServiceProviderOrmRegistry(entity.Init),
registry.ServiceProviderOrmEngine(),
registry.ServiceProviderClock(),
registry.ServiceProviderOSS(oss.NewAmazonOSS, exampleOSS.Namespaces),
registry.ServiceProviderJWT(),
registry.ServiceProviderPassword(password.NewSimpleManager),
registry.ServiceProviderSocketRegistry(eventHandlersMap),
registry.ServiceProviderOTP(),
).RegisterDIRequestService(
registry.ServiceProviderOrmEngineForContext(false),
).RegisterRedisPools(&app.RedisPools{Persistent: "default", Cache: "default"}).
RegisterDevPanel(&entity.DevPanelUserEntity{}, middleware.DevPanelRouter).Build()
defer deferFunc()
b := &hitrix.BackgroundProcessor{Server: s}
b.RunAsyncOrmConsumer()
b.RunAsyncRequestLoggerCleaner()
s.RunServer(9999, generated.NewExecutableSchema(generated.Config{Resolvers: &graph.Resolver{}}), func(ginEngine *gin.Engine) {
middleware.RequestLogger(ginEngine, nil)
exampleMiddleware.Router(ginEngine)
middleware.Cors(ginEngine)
}, nil)
}