From b50a0152e1a8cc3ad3bca1e469047fcb02e02630 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 26 Oct 2020 17:56:50 +0800 Subject: [PATCH] 1 --- init.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ sysutils.go | 6 +++++- xvalue.go | 6 ++++++ 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/init.go b/init.go index 5c0487b..76b5620 100644 --- a/init.go +++ b/init.go @@ -1,4 +1,53 @@ package q5 +import ( + "os" + "fmt" + "bufio" +) + +var optDebug = "" +var _optDebug = false +var _optTimeZone int64 = 8 +var q5JsonConfData = "" +var q5JsonConf *XObject +var initLines []string + func init() { + initLines = make([]string, 0) + if optDebug != "" { + _optDebug = true + } + initLines = append(initLines, fmt.Sprintf("optDebug %s _optDebug:%t", optDebug, _optDebug)) + confName := "q5.json" + if Debug() { + confName = "q5.debug.json" + } + if f, err := os.Open(confName); err == nil { + defer f.Close() + q5JsonConfData, _ = bufio.NewReader(f).ReadString(0) + q5JsonConf = NewXoFromJsonStr(q5JsonConfData) + if q5JsonConf.HasKey("timeZone") { + _optTimeZone = q5JsonConf.At("timeZone").AsXValue().GetInt64() + if _optTimeZone < 1 || _optTimeZone > 24 { + panic(confName + + " timeZone error val:" + + NewXInt64(_optTimeZone).GetString()) + } + } + initLines = append(initLines, fmt.Sprintf("%s data:%s", confName, q5JsonConfData)) + initLines = append(initLines, fmt.Sprintf("%s json:%s", confName, q5JsonConf.ToJsonStr())) + } else { + initLines = append(initLines, fmt.Sprintf("%s not found", confName)) + } + initLines = append(initLines, fmt.Sprintf("_optTimeZone:%d", _optTimeZone)) + if Debug() { + for _, val := range initLines { + fmt.Println(val) + } + } +} + +func GetInitLogs() []string { + return initLines } diff --git a/sysutils.go b/sysutils.go index 5281c1b..ab7aa9f 100644 --- a/sysutils.go +++ b/sysutils.go @@ -8,8 +8,12 @@ import ( "reflect" ) +func Debug() bool { + return _optDebug +} + func GetTimeZone() int64 { - return 0 + return _optTimeZone } func GetDaySeconds(seconds int64) int64 { diff --git a/xvalue.go b/xvalue.go index 185ccc1..74e9584 100644 --- a/xvalue.go +++ b/xvalue.go @@ -31,6 +31,12 @@ func NewXInt32(val int32) *XValue { return p } +func NewXInt64(val int64) *XValue { + p := new(XValue) + p.SetInt64(val) + return p +} + func NewXString(val string) *XValue { p := new(XValue) p.SetString(val)