-
Notifications
You must be signed in to change notification settings - Fork 13
/
server.go
45 lines (40 loc) · 1.6 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
package main
import (
"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"
exampleMiddleware "github.com/coretrix/hitrix/example/rest/middleware"
"github.com/coretrix/hitrix/pkg/middleware"
"github.com/coretrix/hitrix/service/component/socket"
"github.com/coretrix/hitrix/service/registry"
"github.com/gin-gonic/gin"
)
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.ServiceDefinitionOrmRegistry(entity.Init),
registry.ServiceDefinitionOrmEngine(),
registry.OSSGoogle(map[string]uint64{"test": 1}),
registry.ServiceProviderJWT(),
registry.ServiceProviderPassword(),
registry.ServiceSocketRegistry(eventHandlersMap),
).RegisterDIRequestService(
registry.ServiceDefinitionOrmEngineForContext(false),
).
RegisterDevPanel(&entity.AdminUserEntity{}, middleware.Router, nil, nil).Build()
defer deferFunc()
b := &hitrix.BackgroundProcessor{Server: s}
b.RunAsyncOrmConsumer()
s.RunServer(9999, generated.NewExecutableSchema(generated.Config{Resolvers: &graph.Resolver{}}), func(ginEngine *gin.Engine) {
exampleMiddleware.Router(ginEngine)
middleware.Cors(ginEngine)
}, nil)
}