This repository has been archived by the owner on Jan 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
project.go
58 lines (46 loc) · 1.42 KB
/
project.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
package project
import (
"go-app/app/errors/BLError"
"golang.org/x/net/context"
"go-app/app/config/taxonomy"
"go-app/app/vo/ProjectVO"
"go-app/service/internal/vo/PingVO"
"go-app/service/ping"
cache "go-app/service/internal/cache/project"
ds "go-app/service/internal/datastore/Project"
)
// Add creates new project entity in DataStore
// and performs cache invalidation for projects slice in cache.
func Add(ctx context.Context, vo ProjectVO.Instance) {
e := ds.Get(ctx, vo.GetName())
if e != (ds.Entity{}) {
BLError.Panicf("Project name (ID) is not available.")
}
tryToPing(ctx, vo.GetURL())
ds.Add(ctx, vo)
cache.InvalidateCache(ctx)
}
func tryToPing(ctx context.Context, url string) {
vo := PingVO.Instance{URL: url, Method: taxonomy.MethodGet}
err := ping.Try(ctx, vo)
if err != nil {
BLError.Panicf("HTTP client failed to perform request by this url.")
}
}
// Update performs project update in DataStore
// and performs cache invalidation for projects slice in cache.
func Update(ctx context.Context, vo ProjectVO.Instance) {
ds.Update(ctx, vo)
cache.InvalidateCache(ctx)
}
// GetAll gets slice with all available projects.
// Performs read from DataStore & cache maintenance.
func GetAll(ctx context.Context) []ds.Entity {
fromCache := cache.GetProjectsAll(ctx)
if fromCache != nil {
return fromCache
}
fromDataStore := ds.GetAll(ctx)
cache.AddProjectsAll(ctx, fromDataStore)
return fromDataStore
}