mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
Improved import, by group improt.
This commit is contained in:
@ -29,7 +29,7 @@ func EncodeToString(src []byte) string {
|
||||
return string(Encode(src))
|
||||
}
|
||||
|
||||
// EncryptFile encodes file content of `path` using BASE64 algorithms.
|
||||
// EncodeFile encodes file content of `path` using BASE64 algorithms.
|
||||
func EncodeFile(path string) ([]byte, error) {
|
||||
content, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
@ -99,7 +99,7 @@ func MustDecodeString(data string) []byte {
|
||||
return result
|
||||
}
|
||||
|
||||
// DecodeString decodes string with BASE64 algorithm.
|
||||
// DecodeToString decodes string with BASE64 algorithm.
|
||||
func DecodeToString(data string) (string, error) {
|
||||
b, err := DecodeString(data)
|
||||
return string(b), err
|
||||
|
||||
@ -7,9 +7,9 @@
|
||||
package gbase64_test
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/debug/gdebug"
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/v2/debug/gdebug"
|
||||
"github.com/gogf/gf/v2/encoding/gbase64"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
)
|
||||
|
||||
@ -8,14 +8,18 @@ package gbinary
|
||||
|
||||
// NOTE: THIS IS AN EXPERIMENTAL FEATURE!
|
||||
|
||||
// 二进制位(0|1)
|
||||
// Bit Binary bit (0 | 1) 二进制位(0|1)
|
||||
type Bit int8
|
||||
|
||||
// EncodeBits .
|
||||
// Default coding
|
||||
// 默认编码
|
||||
func EncodeBits(bits []Bit, i int, l int) []Bit {
|
||||
return EncodeBitsWithUint(bits, uint(i), l)
|
||||
}
|
||||
|
||||
// EncodeBitsWithUint .
|
||||
// Merge ui bitwise into the bits array and occupy the length length bits (Note: binary 0 | 1 digits are stored in the uis array)
|
||||
// 将ui按位合并到bits数组中,并占length长度位(注意:uis数组中存放的是二进制的0|1数字)
|
||||
func EncodeBitsWithUint(bits []Bit, ui uint, l int) []Bit {
|
||||
a := make([]Bit, l)
|
||||
@ -25,11 +29,12 @@ func EncodeBitsWithUint(bits []Bit, ui uint, l int) []Bit {
|
||||
}
|
||||
if bits != nil {
|
||||
return append(bits, a...)
|
||||
} else {
|
||||
return a
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
// EncodeBitsToBytes .
|
||||
// Convert bits to [] byte, encode from left to right, and add less than 1 byte from 0 to the end.
|
||||
// 将bits转换为[]byte,从左至右进行编码,不足1 byte按0往末尾补充
|
||||
func EncodeBitsToBytes(bits []Bit) []byte {
|
||||
if len(bits)%8 != 0 {
|
||||
@ -44,6 +49,8 @@ func EncodeBitsToBytes(bits []Bit) []byte {
|
||||
return b
|
||||
}
|
||||
|
||||
// DecodeBits .
|
||||
// Resolve to int
|
||||
// 解析为int
|
||||
func DecodeBits(bits []Bit) int {
|
||||
v := 0
|
||||
@ -53,6 +60,8 @@ func DecodeBits(bits []Bit) int {
|
||||
return v
|
||||
}
|
||||
|
||||
// DecodeBitsToUint .
|
||||
// Resolve to uint
|
||||
// 解析为uint
|
||||
func DecodeBitsToUint(bits []Bit) uint {
|
||||
v := uint(0)
|
||||
@ -62,6 +71,8 @@ func DecodeBitsToUint(bits []Bit) uint {
|
||||
return v
|
||||
}
|
||||
|
||||
// DecodeBytesToBits .
|
||||
// Parsing [] byte into character array [] uint8
|
||||
// 解析[]byte为字位数组[]uint8
|
||||
func DecodeBytesToBits(bs []byte) []Bit {
|
||||
bits := make([]Bit, 0)
|
||||
|
||||
@ -22,11 +22,11 @@ package gcharset
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/internal/intlog"
|
||||
"io/ioutil"
|
||||
|
||||
"golang.org/x/text/encoding"
|
||||
"golang.org/x/text/encoding/ianaindex"
|
||||
"golang.org/x/text/transform"
|
||||
|
||||
@ -9,8 +9,9 @@ package gcompress
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"io"
|
||||
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
)
|
||||
|
||||
// Gzip compresses `data` using gzip algorithm.
|
||||
@ -91,7 +92,7 @@ func UnGzip(data []byte) ([]byte, error) {
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
// UnGzip decompresses file `src` to `dst` using gzip algorithm.
|
||||
// UnGzipFile decompresses file `src` to `dst` using gzip algorithm.
|
||||
func UnGzipFile(src, dst string) error {
|
||||
srcFile, err := gfile.Open(src)
|
||||
if err != nil {
|
||||
|
||||
@ -7,12 +7,12 @@
|
||||
package gcompress_test
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/debug/gdebug"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/v2/debug/gdebug"
|
||||
"github.com/gogf/gf/v2/encoding/gcompress"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
)
|
||||
|
||||
|
||||
@ -8,12 +8,12 @@ package gcompress_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/v2/debug/gdebug"
|
||||
"github.com/gogf/gf/v2/encoding/gcompress"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
)
|
||||
|
||||
|
||||
@ -10,13 +10,14 @@ import (
|
||||
"archive/zip"
|
||||
"bytes"
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/internal/intlog"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/v2/internal/intlog"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
)
|
||||
|
||||
// ZipPath compresses `paths` to `dest` using zip compressing algorithm.
|
||||
|
||||
@ -7,10 +7,10 @@
|
||||
package ghtml_test
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/v2/encoding/ghtml"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
)
|
||||
|
||||
|
||||
@ -11,11 +11,12 @@ import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/internal/json"
|
||||
"io"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Decode converts INI format to map.
|
||||
|
||||
@ -7,10 +7,11 @@
|
||||
package gini_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/v2/encoding/gini"
|
||||
"github.com/gogf/gf/v2/encoding/gjson"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var iniContent = `
|
||||
|
||||
@ -8,12 +8,12 @@
|
||||
package gjson
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/internal/utils"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/v2/internal/rwmutex"
|
||||
"github.com/gogf/gf/v2/internal/utils"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
@ -8,11 +8,11 @@ package gjson
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/v2/container/gvar"
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/util/gutil"
|
||||
|
||||
"github.com/gogf/gf/v2/container/gvar"
|
||||
)
|
||||
|
||||
// Interface returns the json value.
|
||||
|
||||
@ -8,18 +8,17 @@ package gjson
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/internal/utils"
|
||||
"reflect"
|
||||
|
||||
"github.com/gogf/gf/v2/internal/json"
|
||||
|
||||
"github.com/gogf/gf/v2/encoding/gini"
|
||||
"github.com/gogf/gf/v2/encoding/gtoml"
|
||||
"github.com/gogf/gf/v2/encoding/gxml"
|
||||
"github.com/gogf/gf/v2/encoding/gyaml"
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/internal/json"
|
||||
"github.com/gogf/gf/v2/internal/rwmutex"
|
||||
"github.com/gogf/gf/v2/internal/utils"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/text/gregex"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
@ -178,7 +177,7 @@ func LoadContentType(dataType string, data interface{}, safe ...bool) (*Json, er
|
||||
if len(content) == 0 {
|
||||
return New(nil, safe...), nil
|
||||
}
|
||||
//ignore UTF8-BOM
|
||||
// ignore UTF8-BOM
|
||||
if content[0] == 0xEF && content[1] == 0xBB && content[2] == 0xBF {
|
||||
content = content[3:]
|
||||
}
|
||||
@ -217,7 +216,7 @@ func loadContentTypeWithOptions(dataType string, data interface{}, options Optio
|
||||
if len(content) == 0 {
|
||||
return NewWithOptions(nil, options), nil
|
||||
}
|
||||
//ignore UTF8-BOM
|
||||
// ignore UTF8-BOM
|
||||
if content[0] == 0xEF && content[1] == 0xBB && content[2] == 0xBF {
|
||||
content = content[3:]
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ package gjson
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/gogf/gf/v2/internal/json"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
@ -43,7 +44,7 @@ func DecodeTo(data interface{}, v interface{}) error {
|
||||
// Do not use number, it converts float64 to json.Number type,
|
||||
// which actually a string type. It causes converting issue for other data formats,
|
||||
// for example: yaml.
|
||||
//decoder.UseNumber()
|
||||
// decoder.UseNumber()
|
||||
return decoder.Decode(v)
|
||||
}
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@ package gjson_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/v2/encoding/gjson"
|
||||
)
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@ package gjson_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/v2/encoding/gjson"
|
||||
)
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@ package gjson_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/v2/debug/gdebug"
|
||||
"github.com/gogf/gf/v2/encoding/gjson"
|
||||
)
|
||||
|
||||
@ -8,6 +8,7 @@ package gjson_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/v2/encoding/gjson"
|
||||
)
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@ package gjson_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/v2/encoding/gjson"
|
||||
)
|
||||
|
||||
|
||||
@ -7,9 +7,9 @@
|
||||
package gjson_test
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/container/gmap"
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/v2/container/gmap"
|
||||
"github.com/gogf/gf/v2/encoding/gjson"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
@ -372,7 +372,7 @@ func Test_Convert2(t *testing.T) {
|
||||
err := j.Var().Scan(&name)
|
||||
t.Assert(err, nil)
|
||||
t.Assert(name.Name, "gf")
|
||||
//j.Dump()
|
||||
// j.Dump()
|
||||
t.Assert(err, nil)
|
||||
|
||||
j = gjson.New(`{"person":{"name":"gf"}}`)
|
||||
@ -381,7 +381,7 @@ func Test_Convert2(t *testing.T) {
|
||||
t.Assert(name.Name, "gf")
|
||||
|
||||
j = gjson.New(`{"name":"gf""}`)
|
||||
//j.Dump()
|
||||
// j.Dump()
|
||||
t.Assert(err, nil)
|
||||
|
||||
j = gjson.New(`[1,2,3]`)
|
||||
|
||||
@ -7,13 +7,13 @@
|
||||
package gjson_test
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/internal/json"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/v2/encoding/gjson"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/internal/json"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
func TestJson_UnmarshalJSON(t *testing.T) {
|
||||
|
||||
@ -7,8 +7,9 @@
|
||||
package gjson
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
)
|
||||
|
||||
func Test_checkDataType(t *testing.T) {
|
||||
@ -80,11 +81,11 @@ dd = 11
|
||||
"gf.gvalid.rule.not-in" = "The :attribute value is not in acceptable range"
|
||||
"gf.gvalid.rule.regex" = "The :attribute value is invalid"
|
||||
`)
|
||||
//fmt.Println(gregex.IsMatch(`^[\s\t\n\r]*[\w\-]+\s*:\s*".+"`, data))
|
||||
//fmt.Println(gregex.IsMatch(`^[\s\t\n\r]*[\w\-]+\s*:\s*\w+`, data))
|
||||
//fmt.Println(gregex.IsMatch(`[\s\t\n\r]+[\w\-]+\s*:\s*".+"`, data))
|
||||
//fmt.Println(gregex.IsMatch(`[\n\r]+[\w\-\s\t]+\s*:\s*\w+`, data))
|
||||
//fmt.Println(gregex.MatchString(`[\n\r]+[\w\-\s\t]+\s*:\s*\w+`, string(data)))
|
||||
// fmt.Println(gregex.IsMatch(`^[\s\t\n\r]*[\w\-]+\s*:\s*".+"`, data))
|
||||
// fmt.Println(gregex.IsMatch(`^[\s\t\n\r]*[\w\-]+\s*:\s*\w+`, data))
|
||||
// fmt.Println(gregex.IsMatch(`[\s\t\n\r]+[\w\-]+\s*:\s*".+"`, data))
|
||||
// fmt.Println(gregex.IsMatch(`[\n\r]+[\w\-\s\t]+\s*:\s*\w+`, data))
|
||||
// fmt.Println(gregex.MatchString(`[\n\r]+[\w\-\s\t]+\s*:\s*\w+`, string(data)))
|
||||
t.Assert(checkDataType(data), "toml")
|
||||
})
|
||||
|
||||
|
||||
@ -7,11 +7,12 @@
|
||||
package gjson_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/v2/encoding/gjson"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_ToJson(t *testing.T) {
|
||||
|
||||
@ -8,12 +8,12 @@ package gjson_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/v2/encoding/gjson"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
)
|
||||
|
||||
func Test_Set1(t *testing.T) {
|
||||
|
||||
@ -7,9 +7,10 @@
|
||||
package gjson_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/v2/encoding/gjson"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_GetScan(t *testing.T) {
|
||||
|
||||
@ -9,9 +9,9 @@ package gtoml
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/gogf/gf/v2/internal/json"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"github.com/gogf/gf/v2/internal/json"
|
||||
)
|
||||
|
||||
func Encode(v interface{}) ([]byte, error) {
|
||||
|
||||
@ -6,10 +6,11 @@
|
||||
package gtoml_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/v2/encoding/gjson"
|
||||
"github.com/gogf/gf/v2/encoding/gtoml"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var tomlStr string = `
|
||||
|
||||
@ -8,11 +8,11 @@ package gxml_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/gogf/gf/v2/encoding/gjson"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/v2/encoding/gcharset"
|
||||
"github.com/gogf/gf/v2/encoding/gjson"
|
||||
"github.com/gogf/gf/v2/encoding/gxml"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
)
|
||||
@ -146,7 +146,7 @@ func Test_Encode(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("encode error.")
|
||||
}
|
||||
//t.Logf("%s\n", string(xmlStr))
|
||||
// t.Logf("%s\n", string(xmlStr))
|
||||
|
||||
res := `<root><bool>true</bool><float>100.92</float><int>123</int><string>hello world</string></root>`
|
||||
if string(xmlStr) != res {
|
||||
@ -169,7 +169,7 @@ func Test_EncodeIndent(t *testing.T) {
|
||||
t.Errorf("encodeWithIndent error.")
|
||||
}
|
||||
|
||||
//t.Logf("%s\n", string(xmlStr))
|
||||
// t.Logf("%s\n", string(xmlStr))
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -10,9 +10,8 @@ package gyaml
|
||||
import (
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/internal/json"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
func Encode(value interface{}) (out []byte, err error) {
|
||||
|
||||
@ -7,13 +7,12 @@
|
||||
package gyaml_test
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/encoding/gjson"
|
||||
"github.com/gogf/gf/v2/internal/json"
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
|
||||
"github.com/gogf/gf/v2/encoding/gjson"
|
||||
"github.com/gogf/gf/v2/encoding/gyaml"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/internal/json"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user