Commit f4a05767 authored by Ajit Jagtap's avatar Ajit Jagtap
Browse files

Merge branch 'Roshanp-GjsonHelpermdl' into 'devbranch'

Roshanp gjson helpermdl

See merge request !53
parents fcce3c1c 9023c37c
2 merge requests!54Devbranch,!53Roshanp gjson helpermdl
Showing with 20 additions and 19 deletions
......@@ -6,14 +6,8 @@
// Package fdb Prod this will compile only for production envirnoment
package fdb
import (
"time"
"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/cachemdl"
)
func init() {
Mastercache = cachemdl.CacheGCHelper{}
//FIXME: Below hardcoded values need better number
Mastercache.Setup(5000, time.Second*500)
}
// func init() {
// Mastercache = cachemdl.CacheGCHelper{}
// //FIXME: Below hardcoded values need better number
// Mastercache.Setup(5000, time.Second*500)
// }
......@@ -6,12 +6,11 @@ import (
"unicode/utf16"
"unicode/utf8"
"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/loggermdl"
"github.com/tidwall/gjson"
)
// GetInterface - return interface of rs
func GetInterface(t *gjson.Result) interface{} {
func GetInterface(t *gjson.Result, timeStampKeys ...string) interface{} {
if t.Type == gjson.String {
return t.Str
}
......@@ -23,7 +22,7 @@ func GetInterface(t *gjson.Result) interface{} {
case gjson.Number:
return t.Num
case gjson.JSON:
r := arrayOrMap(t, 0, true)
r := arrayOrMap(t, 0, true, timeStampKeys...)
if r.vc == '{' {
return r.oi
} else if r.vc == '[' {
......@@ -43,7 +42,7 @@ type arrayOrMapResult struct {
vc byte
}
func arrayOrMap(t *gjson.Result, vc byte, valueize bool) (r arrayOrMapResult) {
func arrayOrMap(t *gjson.Result, vc byte, valueize bool, timeStampKeys ...string) (r arrayOrMapResult) {
var json = t.Raw
var i int
var value gjson.Result
......@@ -131,10 +130,9 @@ func arrayOrMap(t *gjson.Result, vc byte, valueize bool) (r arrayOrMapResult) {
} else {
if valueize {
if _, ok := r.oi[key.Str]; !ok {
if len(value.String()) == len(time.RFC3339Nano) {
if len(timeStampKeys) > 0 && detectTimeStampKey(key.Str, timeStampKeys) {
t, err := time.Parse(time.RFC3339Nano, value.String())
if err == nil {
loggermdl.LogError(value, t)
r.oi[key.Str] = t.Local()
} else {
r.oi[key.Str] = value.Value()
......@@ -162,6 +160,15 @@ end:
return
}
func detectTimeStampKey(key string, timeStamppKeys []string) bool {
for _, timeStampKey := range timeStamppKeys {
if timeStampKey == key {
return true
}
}
return false
}
func squash(json string) string {
// expects that the lead character is a '[' or '{'
// squash the value, ignoring all nested arrays and objects.
......
//+build !prod
// +build !prod
//@author Ajit Jagtap
//@version Thu Jul 05 2018 06:40:34 GMT+0530 (IST)
......
//+build prod
// +build prod
package loggermdl
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment