-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
77 lines (62 loc) · 1.92 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package repositories
import (
"sync"
"cms.csesoc.unsw.edu.au/database/contexts"
"github.com/google/uuid"
)
// Start up a database connection with a provided context
// TODO: this is technical a global shared variable and should be treated as such, this should be wrapped in a mutex
// or eliminated of entirely :D
var contextLock = sync.Mutex{}
var context contexts.DatabaseContext = nil
// Open constructors available for everyone
// NewFilesystemRepo instantiates a new file system repository with the current embedded context
func NewFilesystemRepo() FilesystemRepository {
return filesystemRepository{
embeddedContext{getContext()},
}
}
// NewGroupsRepo instantiates a new groups repository
func NewGroupsRepo() GroupsRepository {
return groupsRepository{
embeddedContext{getContext()},
}
}
// NewFrontendsRepo instantiates a new frontends repository
func NewFrontendsRepo() FrontendsRepository {
return frontendsRepository{
embeddedContext{getContext()},
}
}
// NewPersonRepo instantiates a new person repository
func NewPersonRepo(frontendId uuid.UUID) PersonRepository {
return personRepository{
frontendId,
embeddedContext{getContext()},
}
}
// NewDockerPublishedRepo instantiates a new published docker volume repository
func NewUnpublishedRepo() UnpublishedVolumeRepository {
fs, err := newDockerUnpublishedFileSystemRepository()
if err != nil {
// We should always be able to acquire this repository, if we cant then something really bad has happened
panic(err)
}
return fs
}
func NewPublishedRepo() PublishedVolumeRepository {
fs, err := newDockerPublishedFileSystemRepository()
if err != nil {
// We should always be able to acquire this repository, if we cant then something really bad has happened
panic(err)
}
return fs
}
func getContext() contexts.DatabaseContext {
contextLock.Lock()
defer contextLock.Unlock()
if context == nil {
context = contexts.GetDatabaseContext()
}
return context
}