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.Set(rh.ServiceName, *rh) } // GetResponseHeader return response header object func GetResponseHeader(serviceName string) (interface{}, bool) { return responseHeaders.Get(serviceName) }