generated from cyware/cyware-project-template
/
info.go
82 lines (68 loc) · 1.67 KB
/
info.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
78
79
80
81
82
package config
import (
"strings"
"github.com/cyware/ssi-service/pkg/service/framework"
)
const (
ServiceName = "ssi-service"
ServiceVersion = "0.0.3"
APIVersion = "v1"
)
var (
si = &serviceInfo{
name: ServiceName,
description: "The Self Sovereign Identity Service is a RESTful web service that facilitates all things relating" +
" to DIDs, VCs, and related standards-based interactions.",
version: ServiceVersion,
apiVersion: APIVersion,
servicePaths: make(map[framework.Type]string),
}
)
// serviceInfo is intended to be a singleton object for static service info.
// WARNING: it is **NOT** currently thread safe.
type serviceInfo struct {
name string
description string
version string
apiBase string
statusBaseURL string
apiVersion string
servicePaths map[framework.Type]string
}
func Name() string {
return si.name
}
func Description() string {
return si.description
}
func (si *serviceInfo) Version() string {
return si.version
}
func SetAPIBase(url string) {
if strings.LastIndexAny(url, "/") == len(url)-1 {
url = url[:len(url)-1]
}
si.apiBase = url
}
func GetAPIBase() string {
return si.apiBase
}
func SetStatusBase(url string) {
if strings.LastIndexAny(url, "/") == len(url)-1 {
url = url[:len(url)-1]
}
si.statusBaseURL = url
}
func GetStatusBase() string {
return si.statusBaseURL
}
func SetServicePath(service framework.Type, path string) {
// normalize path
if strings.IndexAny(path, "/") == 0 {
path = path[1:]
}
si.servicePaths[service] = strings.Join([]string{si.apiBase, APIVersion, path}, "/")
}
func GetServicePath(service framework.Type) string {
return si.servicePaths[service]
}