Total Lines | 63 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package internal |
||
2 | |||
3 | import ( |
||
4 | "sync" |
||
5 | |||
6 | "github.com/memnix/memnix-rest/app/http/controllers" |
||
7 | ) |
||
8 | |||
9 | // ServiceContainer is the service container interface. |
||
10 | type ServiceContainer interface { |
||
11 | GetUser() controllers.UserController // GetUser returns the user controller. |
||
12 | GetAuth() controllers.AuthController // GetAuth returns the auth controller. |
||
13 | GetJwt() controllers.JwtController // GetJwt returns the jwt controller. |
||
14 | GetOAuth() controllers.OAuthController // GetOAuth returns the oauth controller. |
||
15 | GetDeck() controllers.DeckController // GetDeck returns the deck controller. |
||
16 | } |
||
17 | |||
18 | type kernel struct{} |
||
19 | |||
20 | // GetUser returns the user controller. |
||
21 | func (kernel) GetUser() controllers.UserController { |
||
22 | return InitializeUser() |
||
23 | } |
||
24 | |||
25 | // GetAuth returns the auth controller. |
||
26 | func (kernel) GetAuth() controllers.AuthController { |
||
27 | return InitializeAuth() |
||
28 | } |
||
29 | |||
30 | // GetJwt returns the jwt controller. |
||
31 | func (kernel) GetJwt() controllers.JwtController { |
||
32 | return InitializeJWT() |
||
33 | } |
||
34 | |||
35 | // GetOAuth returns the oauth controller. |
||
36 | func (kernel) GetOAuth() controllers.OAuthController { |
||
37 | return InitializeOAuth() |
||
38 | } |
||
39 | |||
40 | // GetDeck returns the deck controller. |
||
41 | func (kernel) GetDeck() controllers.DeckController { |
||
42 | return InitializeDeck() |
||
43 | } |
||
44 | |||
45 | func (kernel) GetCard() controllers.CardController { |
||
46 | return InitializeCard() |
||
47 | } |
||
48 | |||
49 | func (kernel) GetMcq() controllers.McqController { |
||
50 | return InitializeMcq() |
||
51 | } |
||
52 | |||
53 | var ( |
||
54 | k *kernel // kernel is the service container |
||
55 | containerOnce sync.Once // containerOnce is used to ensure that the service container is only initialized once |
||
56 | ) |
||
57 | |||
58 | // GetServiceContainer returns the service container |
||
59 | func GetServiceContainer() ServiceContainer { |
||
60 | containerOnce.Do(func() { |
||
61 | k = &kernel{} |
||
62 | }) |
||
63 | return k |
||
64 | } |
||
65 |