add glog.Expose for glog; add Trim operation for glog.Logger.Write; fix issue in gjson.Remove for slice

This commit is contained in:
John 2019-06-13 19:29:09 +08:00
parent 55f5e6d7aa
commit 23d404f681
7 changed files with 19 additions and 14 deletions

View File

@ -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
}

View File

@ -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

View File

@ -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 <writer>.
func To(writer io.Writer) *Logger {

View File

@ -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
}

View File

@ -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)

View File

@ -24,5 +24,7 @@ func main() {
glog.SetWriter(&MyWriter{
logger: glog.New(),
})
glog.Debug("DEBUG")
glog.Fatal("FATAL ERROR")
}

View File

@ -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()
}