Newer
Older
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
package routebuildermdl
import (
"time"
"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/cachemdl"
"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/utiliymdl/guidmdl"
)
// Repose Header setting
var responseHeaders cachemdl.FastCacheHelper
func init() {
// TODO: Take all configurations from config module
responseHeaders.Setup(10, time.Minute*10, time.Minute*10)
}
// ResponseHeaders this is struct for Response headers
type ResponseHeaders struct {
ServiceName string
HeaderID string `json:"headerId"`
LCache bool `json:"lCache"`
Methods []responseMethod `json:"methods"`
}
type responseMethod struct {
MethodName string `json:"methodName"`
Data interface{} `json:"data"`
}
type responseData struct {
Result interface{} `json:"result"`
Error string `json:"error"`
ResponseHeader interface{} `json:"reponseHeader"`
}
// CreateResponseHeader create an instance of response header for service
func CreateResponseHeader(serviceName string) *ResponseHeaders {
lCacheflag := false
responseHeader, ok := responseHeaders.Get(serviceName)
if ok {
lCacheflag = responseHeader.(ResponseHeaders).LCache
// TODO: Delete functionality
// responseHeaders.Delete(serviceName)
}
rh := &ResponseHeaders{}
rh.ServiceName = serviceName
rh.LCache = lCacheflag
rh.HeaderID = guidmdl.GetGUID()
return rh
}
// EnableReponseCache cache this response in local storge
func (rh *ResponseHeaders) EnableReponseCache() *ResponseHeaders {
rh.LCache = true
return rh
}
// DisableReponseCache cache this response in local storge
func (rh *ResponseHeaders) DisableReponseCache() *ResponseHeaders {
rh.LCache = false
return rh
}
// AddMethod add method and data in response
func (rh *ResponseHeaders) AddMethod(name string, data interface{}) *ResponseHeaders {
rh.Methods = append(rh.Methods, responseMethod{MethodName: name, Data: data})
return rh
}
// SetResponseHeader set response headers in cache
func (rh *ResponseHeaders) SetResponseHeader() {
responseHeaders.SetNoExpiration(rh.ServiceName, *rh)
}
// GetResponseHeader return response header object
func GetResponseHeader(serviceName string) (interface{}, bool) {
return responseHeaders.Get(serviceName)
}