From 23d404f6811f884c4a19db073a0a0fa9e312d63b Mon Sep 17 00:00:00 2001 From: John Date: Thu, 13 Jun 2019 19:29:09 +0800 Subject: [PATCH] add glog.Expose for glog; add Trim operation for glog.Logger.Write; fix issue in gjson.Remove for slice --- g/encoding/gjson/gjson.go | 6 +++++- g/os/glog/glog.go | 2 -- g/os/glog/glog_chaining.go | 5 +++++ g/os/glog/glog_logger_writer.go | 4 +++- g/util/gconv/gconv.go | 3 --- geg/os/glog/glog_writer_hook.go | 2 ++ geg/other/test.go | 11 ++++------- 7 files changed, 19 insertions(+), 14 deletions(-) diff --git a/g/encoding/gjson/gjson.go b/g/encoding/gjson/gjson.go index 3b63289bd..fdb362518 100644 --- a/g/encoding/gjson/gjson.go +++ b/g/encoding/gjson/gjson.go @@ -108,7 +108,11 @@ func (j *Json) setValue(pattern string, value interface{}, removed bool) error { if len((*pointer).([]interface{})) > valn { if removed && value == nil { // 删除数据元素 - j.setPointerWithValue(pparent, array[i - 1], append((*pointer).([]interface{})[ : valn], (*pointer).([]interface{})[valn + 1 : ]...)) + if pparent == nil { + *pointer = append((*pointer).([]interface{})[ : valn], (*pointer).([]interface{})[valn + 1 : ]...) + } else { + j.setPointerWithValue(pparent, array[i - 1], append((*pointer).([]interface{})[ : valn], (*pointer).([]interface{})[valn + 1 : ]...)) + } } else { (*pointer).([]interface{})[valn] = value } diff --git a/g/os/glog/glog.go b/g/os/glog/glog.go index ad59cad70..45f39011f 100644 --- a/g/os/glog/glog.go +++ b/g/os/glog/glog.go @@ -3,8 +3,6 @@ // This Source Code Form is subject to the terms of the MIT License. // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. -// -// @author john, zseeker // Package glog implements powerful and easy-to-use levelled logging functionality. package glog diff --git a/g/os/glog/glog_chaining.go b/g/os/glog/glog_chaining.go index 471c96701..a6c8c3f8a 100644 --- a/g/os/glog/glog_chaining.go +++ b/g/os/glog/glog_chaining.go @@ -10,6 +10,11 @@ import ( "io" ) +// Expose returns the default logger of glog. +func Expose() *Logger { + return logger +} + // To is a chaining function, // which redirects current logging content output to the sepecified . func To(writer io.Writer) *Logger { diff --git a/g/os/glog/glog_logger_writer.go b/g/os/glog/glog_logger_writer.go index d2eef9dee..aa06df4b4 100644 --- a/g/os/glog/glog_logger_writer.go +++ b/g/os/glog/glog_logger_writer.go @@ -6,9 +6,11 @@ package glog +import "bytes" + // Write implements the io.Writer interface. // It just prints the content using Print. func (l *Logger) Write(p []byte) (n int, err error) { - l.Header(false).Print(string(p)) + l.Header(false).Print(string(bytes.TrimRight(p, "\r\n"))) return len(p), nil } \ No newline at end of file diff --git a/g/util/gconv/gconv.go b/g/util/gconv/gconv.go index 635645a6d..708ab51bb 100644 --- a/g/util/gconv/gconv.go +++ b/g/util/gconv/gconv.go @@ -241,9 +241,6 @@ func Int64(i interface{}) int64 { if i == nil { return 0 } - if v, ok := i.(int64); ok { - return v - } switch value := i.(type) { case int: return int64(value) case int8: return int64(value) diff --git a/geg/os/glog/glog_writer_hook.go b/geg/os/glog/glog_writer_hook.go index 6bef33449..ccb649b66 100644 --- a/geg/os/glog/glog_writer_hook.go +++ b/geg/os/glog/glog_writer_hook.go @@ -24,5 +24,7 @@ func main() { glog.SetWriter(&MyWriter{ logger: glog.New(), }) + glog.Debug("DEBUG") glog.Fatal("FATAL ERROR") + } diff --git a/geg/other/test.go b/geg/other/test.go index 983b019a8..c5206b690 100644 --- a/geg/other/test.go +++ b/geg/other/test.go @@ -1,14 +1,11 @@ package main import ( - "github.com/gogf/gf/g/container/garray" - "github.com/gogf/gf/g/test/gtest" + "github.com/gogf/gf/g/encoding/gjson" ) func main() { - a1:=[]string{"a", "d", "c","b"} - - s1 :=garray.NewSortedStringArrayFromCopy(a1,true) - - gtest.Assert(s1.Slice(),[]string{"a", "b", "c","d"}) + j := gjson.New(`[1,2,3]`) + j.Remove("1") + j.Dump() }