mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
unify error package to gerror
This commit is contained in:
@ -8,8 +8,8 @@ package garray
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"github.com/gogf/gf/internal/empty"
|
||||
"github.com/gogf/gf/internal/json"
|
||||
"github.com/gogf/gf/text/gstr"
|
||||
@ -123,7 +123,7 @@ func (a *Array) Set(index int, value interface{}) error {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
if index < 0 || index >= len(a.array) {
|
||||
return errors.New(fmt.Sprintf("index %d out of array range %d", index, len(a.array)))
|
||||
return gerror.Newf("index %d out of array range %d", index, len(a.array))
|
||||
}
|
||||
a.array[index] = value
|
||||
return nil
|
||||
@ -176,7 +176,7 @@ func (a *Array) InsertBefore(index int, value interface{}) error {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
if index < 0 || index >= len(a.array) {
|
||||
return errors.New(fmt.Sprintf("index %d out of array range %d", index, len(a.array)))
|
||||
return gerror.Newf("index %d out of array range %d", index, len(a.array))
|
||||
}
|
||||
rear := append([]interface{}{}, a.array[index:]...)
|
||||
a.array = append(a.array[0:index], value)
|
||||
@ -189,7 +189,7 @@ func (a *Array) InsertAfter(index int, value interface{}) error {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
if index < 0 || index >= len(a.array) {
|
||||
return errors.New(fmt.Sprintf("index %d out of array range %d", index, len(a.array)))
|
||||
return gerror.Newf("index %d out of array range %d", index, len(a.array))
|
||||
}
|
||||
rear := append([]interface{}{}, a.array[index+1:]...)
|
||||
a.array = append(a.array[0:index+1], value)
|
||||
@ -545,7 +545,7 @@ func (a *Array) Fill(startIndex int, num int, value interface{}) error {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
if startIndex < 0 || startIndex > len(a.array) {
|
||||
return errors.New(fmt.Sprintf("index %d out of array range %d", startIndex, len(a.array)))
|
||||
return gerror.Newf("index %d out of array range %d", startIndex, len(a.array))
|
||||
}
|
||||
for i := startIndex; i < startIndex+num; i++ {
|
||||
if i > len(a.array)-1 {
|
||||
|
||||
@ -8,8 +8,8 @@ package garray
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"github.com/gogf/gf/internal/json"
|
||||
"math"
|
||||
"sort"
|
||||
@ -104,7 +104,7 @@ func (a *IntArray) Set(index int, value int) error {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
if index < 0 || index >= len(a.array) {
|
||||
return errors.New(fmt.Sprintf("index %d out of array range %d", index, len(a.array)))
|
||||
return gerror.Newf("index %d out of array range %d", index, len(a.array))
|
||||
}
|
||||
a.array[index] = value
|
||||
return nil
|
||||
@ -175,7 +175,7 @@ func (a *IntArray) InsertBefore(index int, value int) error {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
if index < 0 || index >= len(a.array) {
|
||||
return errors.New(fmt.Sprintf("index %d out of array range %d", index, len(a.array)))
|
||||
return gerror.Newf("index %d out of array range %d", index, len(a.array))
|
||||
}
|
||||
rear := append([]int{}, a.array[index:]...)
|
||||
a.array = append(a.array[0:index], value)
|
||||
@ -188,7 +188,7 @@ func (a *IntArray) InsertAfter(index int, value int) error {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
if index < 0 || index >= len(a.array) {
|
||||
return errors.New(fmt.Sprintf("index %d out of array range %d", index, len(a.array)))
|
||||
return gerror.Newf("index %d out of array range %d", index, len(a.array))
|
||||
}
|
||||
rear := append([]int{}, a.array[index+1:]...)
|
||||
a.array = append(a.array[0:index+1], value)
|
||||
@ -559,7 +559,7 @@ func (a *IntArray) Fill(startIndex int, num int, value int) error {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
if startIndex < 0 || startIndex > len(a.array) {
|
||||
return errors.New(fmt.Sprintf("index %d out of array range %d", startIndex, len(a.array)))
|
||||
return gerror.Newf("index %d out of array range %d", startIndex, len(a.array))
|
||||
}
|
||||
for i := startIndex; i < startIndex+num; i++ {
|
||||
if i > len(a.array)-1 {
|
||||
|
||||
@ -8,8 +8,7 @@ package garray
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"github.com/gogf/gf/internal/json"
|
||||
"github.com/gogf/gf/text/gstr"
|
||||
"math"
|
||||
@ -91,7 +90,7 @@ func (a *StrArray) Set(index int, value string) error {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
if index < 0 || index >= len(a.array) {
|
||||
return errors.New(fmt.Sprintf("index %d out of array range %d", index, len(a.array)))
|
||||
return gerror.Newf("index %d out of array range %d", index, len(a.array))
|
||||
}
|
||||
a.array[index] = value
|
||||
return nil
|
||||
@ -163,7 +162,7 @@ func (a *StrArray) InsertBefore(index int, value string) error {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
if index < 0 || index >= len(a.array) {
|
||||
return errors.New(fmt.Sprintf("index %d out of array range %d", index, len(a.array)))
|
||||
return gerror.Newf("index %d out of array range %d", index, len(a.array))
|
||||
}
|
||||
rear := append([]string{}, a.array[index:]...)
|
||||
a.array = append(a.array[0:index], value)
|
||||
@ -176,7 +175,7 @@ func (a *StrArray) InsertAfter(index int, value string) error {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
if index < 0 || index >= len(a.array) {
|
||||
return errors.New(fmt.Sprintf("index %d out of array range %d", index, len(a.array)))
|
||||
return gerror.Newf("index %d out of array range %d", index, len(a.array))
|
||||
}
|
||||
rear := append([]string{}, a.array[index+1:]...)
|
||||
a.array = append(a.array[0:index+1], value)
|
||||
@ -563,7 +562,7 @@ func (a *StrArray) Fill(startIndex int, num int, value string) error {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
if startIndex < 0 || startIndex > len(a.array) {
|
||||
return errors.New(fmt.Sprintf("index %d out of array range %d", startIndex, len(a.array)))
|
||||
return gerror.Newf("index %d out of array range %d", startIndex, len(a.array))
|
||||
}
|
||||
for i := startIndex; i < startIndex+num; i++ {
|
||||
if i > len(a.array)-1 {
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
package gpool
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/container/glist"
|
||||
@ -66,7 +66,7 @@ func New(ttl time.Duration, newFunc NewFunc, expireFunc ...ExpireFunc) *Pool {
|
||||
// Put puts an item to pool.
|
||||
func (p *Pool) Put(value interface{}) error {
|
||||
if p.closed.Val() {
|
||||
return errors.New("pool is closed")
|
||||
return gerror.New("pool is closed")
|
||||
}
|
||||
item := &poolItem{
|
||||
value: value,
|
||||
@ -117,7 +117,7 @@ func (p *Pool) Get() (interface{}, error) {
|
||||
if p.NewFunc != nil {
|
||||
return p.NewFunc()
|
||||
}
|
||||
return nil, errors.New("pool is empty")
|
||||
return nil, gerror.New("pool is empty")
|
||||
}
|
||||
|
||||
// Size returns the count of available items of pool.
|
||||
|
||||
@ -11,7 +11,7 @@ import (
|
||||
"bytes"
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"errors"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -63,7 +63,7 @@ func DecryptCBC(cipherText []byte, key []byte, iv ...[]byte) ([]byte, error) {
|
||||
}
|
||||
blockSize := block.BlockSize()
|
||||
if len(cipherText) < blockSize {
|
||||
return nil, errors.New("cipherText too short")
|
||||
return nil, gerror.New("cipherText too short")
|
||||
}
|
||||
ivValue := ([]byte)(nil)
|
||||
if len(iv) > 0 {
|
||||
@ -72,7 +72,7 @@ func DecryptCBC(cipherText []byte, key []byte, iv ...[]byte) ([]byte, error) {
|
||||
ivValue = []byte(IVDefaultValue)
|
||||
}
|
||||
if len(cipherText)%blockSize != 0 {
|
||||
return nil, errors.New("cipherText is not a multiple of the block size")
|
||||
return nil, gerror.New("cipherText is not a multiple of the block size")
|
||||
}
|
||||
blockModel := cipher.NewCBCDecrypter(block, ivValue)
|
||||
plainText := make([]byte, len(cipherText))
|
||||
@ -93,22 +93,22 @@ func PKCS5Padding(src []byte, blockSize int) []byte {
|
||||
func PKCS5UnPadding(src []byte, blockSize int) ([]byte, error) {
|
||||
length := len(src)
|
||||
if blockSize <= 0 {
|
||||
return nil, errors.New("invalid blocklen")
|
||||
return nil, gerror.New("invalid blocklen")
|
||||
}
|
||||
|
||||
if length%blockSize != 0 || length == 0 {
|
||||
return nil, errors.New("invalid data len")
|
||||
return nil, gerror.New("invalid data len")
|
||||
}
|
||||
|
||||
unpadding := int(src[length-1])
|
||||
if unpadding > blockSize || unpadding == 0 {
|
||||
return nil, errors.New("invalid padding")
|
||||
return nil, gerror.New("invalid padding")
|
||||
}
|
||||
|
||||
padding := src[length-unpadding:]
|
||||
for i := 0; i < unpadding; i++ {
|
||||
if padding[i] != byte(unpadding) {
|
||||
return nil, errors.New("invalid padding")
|
||||
return nil, gerror.New("invalid padding")
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,7 +146,7 @@ func DecryptCFB(cipherText []byte, key []byte, unPadding int, iv ...[]byte) ([]b
|
||||
return nil, err
|
||||
}
|
||||
if len(cipherText) < aes.BlockSize {
|
||||
return nil, errors.New("cipherText too short")
|
||||
return nil, gerror.New("cipherText too short")
|
||||
}
|
||||
ivValue := ([]byte)(nil)
|
||||
if len(iv) > 0 {
|
||||
|
||||
@ -11,7 +11,7 @@ import (
|
||||
"bytes"
|
||||
"crypto/cipher"
|
||||
"crypto/des"
|
||||
"errors"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -66,7 +66,7 @@ func DecryptECB(cipherText []byte, key []byte, padding int) ([]byte, error) {
|
||||
// The length of the <key> should be either 16 or 24 bytes.
|
||||
func EncryptECBTriple(plainText []byte, key []byte, padding int) ([]byte, error) {
|
||||
if len(key) != 16 && len(key) != 24 {
|
||||
return nil, errors.New("key length error")
|
||||
return nil, gerror.New("key length error")
|
||||
}
|
||||
|
||||
text, err := Padding(plainText, padding)
|
||||
@ -100,7 +100,7 @@ func EncryptECBTriple(plainText []byte, key []byte, padding int) ([]byte, error)
|
||||
// The length of the <key> should be either 16 or 24 bytes.
|
||||
func DecryptECBTriple(cipherText []byte, key []byte, padding int) ([]byte, error) {
|
||||
if len(key) != 16 && len(key) != 24 {
|
||||
return nil, errors.New("key length error")
|
||||
return nil, gerror.New("key length error")
|
||||
}
|
||||
|
||||
var newKey []byte
|
||||
@ -138,7 +138,7 @@ func EncryptCBC(plainText []byte, key []byte, iv []byte, padding int) ([]byte, e
|
||||
}
|
||||
|
||||
if len(iv) != block.BlockSize() {
|
||||
return nil, errors.New("iv length invalid")
|
||||
return nil, gerror.New("iv length invalid")
|
||||
}
|
||||
|
||||
text, err := Padding(plainText, padding)
|
||||
@ -161,7 +161,7 @@ func DecryptCBC(cipherText []byte, key []byte, iv []byte, padding int) ([]byte,
|
||||
}
|
||||
|
||||
if len(iv) != block.BlockSize() {
|
||||
return nil, errors.New("iv length invalid")
|
||||
return nil, gerror.New("iv length invalid")
|
||||
}
|
||||
|
||||
text := make([]byte, len(cipherText))
|
||||
@ -179,7 +179,7 @@ func DecryptCBC(cipherText []byte, key []byte, iv []byte, padding int) ([]byte,
|
||||
// EncryptCBCTriple encrypts <plainText> using TripleDES and CBC mode.
|
||||
func EncryptCBCTriple(plainText []byte, key []byte, iv []byte, padding int) ([]byte, error) {
|
||||
if len(key) != 16 && len(key) != 24 {
|
||||
return nil, errors.New("key length invalid")
|
||||
return nil, gerror.New("key length invalid")
|
||||
}
|
||||
|
||||
var newKey []byte
|
||||
@ -196,7 +196,7 @@ func EncryptCBCTriple(plainText []byte, key []byte, iv []byte, padding int) ([]b
|
||||
}
|
||||
|
||||
if len(iv) != block.BlockSize() {
|
||||
return nil, errors.New("iv length invalid")
|
||||
return nil, gerror.New("iv length invalid")
|
||||
}
|
||||
|
||||
text, err := Padding(plainText, padding)
|
||||
@ -214,7 +214,7 @@ func EncryptCBCTriple(plainText []byte, key []byte, iv []byte, padding int) ([]b
|
||||
// DecryptCBCTriple decrypts <cipherText> using TripleDES and CBC mode.
|
||||
func DecryptCBCTriple(cipherText []byte, key []byte, iv []byte, padding int) ([]byte, error) {
|
||||
if len(key) != 16 && len(key) != 24 {
|
||||
return nil, errors.New("key length invalid")
|
||||
return nil, gerror.New("key length invalid")
|
||||
}
|
||||
|
||||
var newKey []byte
|
||||
@ -231,7 +231,7 @@ func DecryptCBCTriple(cipherText []byte, key []byte, iv []byte, padding int) ([]
|
||||
}
|
||||
|
||||
if len(iv) != block.BlockSize() {
|
||||
return nil, errors.New("iv length invalid")
|
||||
return nil, gerror.New("iv length invalid")
|
||||
}
|
||||
|
||||
text := make([]byte, len(cipherText))
|
||||
@ -262,12 +262,12 @@ func Padding(text []byte, padding int) ([]byte, error) {
|
||||
switch padding {
|
||||
case NOPADDING:
|
||||
if len(text)%8 != 0 {
|
||||
return nil, errors.New("text length invalid")
|
||||
return nil, gerror.New("text length invalid")
|
||||
}
|
||||
case PKCS5PADDING:
|
||||
return PaddingPKCS5(text, 8), nil
|
||||
default:
|
||||
return nil, errors.New("padding type error")
|
||||
return nil, gerror.New("padding type error")
|
||||
}
|
||||
|
||||
return text, nil
|
||||
@ -277,12 +277,12 @@ func UnPadding(text []byte, padding int) ([]byte, error) {
|
||||
switch padding {
|
||||
case NOPADDING:
|
||||
if len(text)%8 != 0 {
|
||||
return nil, errors.New("text length invalid")
|
||||
return nil, gerror.New("text length invalid")
|
||||
}
|
||||
case PKCS5PADDING:
|
||||
return UnPaddingPKCS5(text), nil
|
||||
default:
|
||||
return nil, errors.New("padding type error")
|
||||
return nil, gerror.New("padding type error")
|
||||
}
|
||||
return text, nil
|
||||
}
|
||||
|
||||
@ -8,8 +8,8 @@ package gredis
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/gogf/gf/container/gvar"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"github.com/gogf/gf/internal/json"
|
||||
"github.com/gogf/gf/os/gtime"
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
@ -50,7 +50,7 @@ func (c *Conn) do(timeout time.Duration, commandName string, args ...interface{}
|
||||
if timeout > 0 {
|
||||
conn, ok := c.Conn.(redis.ConnWithTimeout)
|
||||
if !ok {
|
||||
return gvar.New(nil), errors.New(`current connection does not support "ConnWithTimeout"`)
|
||||
return gvar.New(nil), gerror.New(`current connection does not support "ConnWithTimeout"`)
|
||||
}
|
||||
return conn.DoWithTimeout(timeout, commandName, args...)
|
||||
}
|
||||
@ -107,7 +107,7 @@ func (c *Conn) ReceiveVar() (*gvar.Var, error) {
|
||||
func (c *Conn) ReceiveVarWithTimeout(timeout time.Duration) (*gvar.Var, error) {
|
||||
conn, ok := c.Conn.(redis.ConnWithTimeout)
|
||||
if !ok {
|
||||
return gvar.New(nil), errors.New(`current connection does not support "ConnWithTimeout"`)
|
||||
return gvar.New(nil), gerror.New(`current connection does not support "ConnWithTimeout"`)
|
||||
}
|
||||
return resultToVar(conn.ReceiveWithTimeout(timeout))
|
||||
}
|
||||
|
||||
@ -21,8 +21,7 @@ package gcharset
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"io/ioutil"
|
||||
|
||||
"golang.org/x/text/encoding"
|
||||
@ -60,11 +59,11 @@ func Convert(dstCharset string, srcCharset string, src string) (dst string, err
|
||||
transform.NewReader(bytes.NewReader([]byte(src)), e.NewDecoder()),
|
||||
)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("%s to utf8 failed. %v", srcCharset, err)
|
||||
return "", gerror.Newf("%s to utf8 failed. %v", srcCharset, err)
|
||||
}
|
||||
src = string(tmp)
|
||||
} else {
|
||||
return dst, errors.New(fmt.Sprintf("unsupport srcCharset: %s", srcCharset))
|
||||
return dst, gerror.Newf("unsupport srcCharset: %s", srcCharset)
|
||||
}
|
||||
}
|
||||
// Do the converting from UTF-8 to <dstCharset>.
|
||||
@ -74,11 +73,11 @@ func Convert(dstCharset string, srcCharset string, src string) (dst string, err
|
||||
transform.NewReader(bytes.NewReader([]byte(src)), e.NewEncoder()),
|
||||
)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("utf to %s failed. %v", dstCharset, err)
|
||||
return "", gerror.Newf("utf to %s failed. %v", dstCharset, err)
|
||||
}
|
||||
dst = string(tmp)
|
||||
} else {
|
||||
return dst, errors.New(fmt.Sprintf("unsupport dstCharset: %s", dstCharset))
|
||||
return dst, gerror.Newf("unsupport dstCharset: %s", dstCharset)
|
||||
}
|
||||
} else {
|
||||
dst = src
|
||||
|
||||
@ -10,8 +10,8 @@ package gini
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"github.com/gogf/gf/internal/json"
|
||||
"io"
|
||||
"strings"
|
||||
@ -70,7 +70,7 @@ func Decode(data []byte) (res map[string]interface{}, err error) {
|
||||
}
|
||||
|
||||
if haveSection == false {
|
||||
return nil, errors.New("failed to parse INI file, section not found")
|
||||
return nil, gerror.New("failed to parse INI file, section not found")
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
@ -8,8 +8,8 @@ package gjson
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"reflect"
|
||||
|
||||
"github.com/gogf/gf/internal/json"
|
||||
@ -264,7 +264,7 @@ func doLoadContentWithOptions(dataType string, data []byte, options Options) (*J
|
||||
return nil, err
|
||||
}
|
||||
default:
|
||||
err = errors.New("unsupported type for loading")
|
||||
err = gerror.New("unsupported type for loading")
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
// Package errors provides simple functions to manipulate errors.
|
||||
// Package gerror provides simple functions to manipulate errors.
|
||||
//
|
||||
// Very note that, this package is quite a base package, which should not import extra
|
||||
// packages except standard packages, to avoid cycle imports.
|
||||
|
||||
@ -8,8 +8,8 @@ package gi18n
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"github.com/gogf/gf/internal/intlog"
|
||||
"strings"
|
||||
"sync"
|
||||
@ -101,7 +101,7 @@ func (m *Manager) SetPath(path string) error {
|
||||
} else {
|
||||
realPath, _ := gfile.Search(path)
|
||||
if realPath == "" {
|
||||
return errors.New(fmt.Sprintf(`%s does not exist`, path))
|
||||
return gerror.Newf(`%s does not exist`, path)
|
||||
}
|
||||
m.options.Path = realPath
|
||||
}
|
||||
|
||||
@ -8,7 +8,6 @@ package ghttp
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"github.com/gogf/gf/internal/intlog"
|
||||
"github.com/gogf/gf/os/gfile"
|
||||
@ -36,7 +35,7 @@ type UploadFiles []*UploadFile
|
||||
// Note that it will OVERWRITE the target file if there's already a same name file exist.
|
||||
func (f *UploadFile) Save(dirPath string, randomlyRename ...bool) (filename string, err error) {
|
||||
if f == nil {
|
||||
return "", errors.New("file is empty, maybe you retrieve it from invalid field name or form enctype")
|
||||
return "", gerror.New("file is empty, maybe you retrieve it from invalid field name or form enctype")
|
||||
}
|
||||
if !gfile.Exists(dirPath) {
|
||||
if err = gfile.Mkdir(dirPath); err != nil {
|
||||
@ -77,7 +76,7 @@ func (f *UploadFile) Save(dirPath string, randomlyRename ...bool) (filename stri
|
||||
// The parameter <randomlyRename> specifies whether randomly renames all the file names.
|
||||
func (fs UploadFiles) Save(dirPath string, randomlyRename ...bool) (filenames []string, err error) {
|
||||
if len(fs) == 0 {
|
||||
return nil, errors.New("file array is empty, maybe you retrieve it from invalid field name or form enctype")
|
||||
return nil, gerror.New("file array is empty, maybe you retrieve it from invalid field name or form enctype")
|
||||
}
|
||||
for _, f := range fs {
|
||||
if filename, err := f.Save(dirPath, randomlyRename...); err != nil {
|
||||
|
||||
@ -9,8 +9,8 @@ package ghttp
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"github.com/gogf/gf/internal/intlog"
|
||||
"github.com/gogf/gf/text/gstr"
|
||||
"os"
|
||||
@ -52,7 +52,7 @@ var serverProcessStatus = gtype.NewInt()
|
||||
// The optional parameter <newExeFilePath> specifies the new binary file for creating process.
|
||||
func RestartAllServer(newExeFilePath ...string) error {
|
||||
if !gracefulEnabled {
|
||||
return errors.New("graceful reload feature is disabled")
|
||||
return gerror.New("graceful reload feature is disabled")
|
||||
}
|
||||
serverActionLocker.Lock()
|
||||
defer serverActionLocker.Unlock()
|
||||
@ -85,9 +85,9 @@ func checkProcessStatus() error {
|
||||
if status > 0 {
|
||||
switch status {
|
||||
case adminActionRestarting:
|
||||
return errors.New("server is restarting")
|
||||
return gerror.New("server is restarting")
|
||||
case adminActionShuttingDown:
|
||||
return errors.New("server is shutting down")
|
||||
return gerror.New("server is shutting down")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@ -98,7 +98,7 @@ func checkProcessStatus() error {
|
||||
func checkActionFrequency() error {
|
||||
interval := gtime.TimestampMilli() - serverActionLastTime.Val()
|
||||
if interval < adminActionIntervalLimit {
|
||||
return errors.New(fmt.Sprintf("too frequent action, please retry in %d ms", adminActionIntervalLimit-interval))
|
||||
return gerror.Newf("too frequent action, please retry in %d ms", adminActionIntervalLimit-interval)
|
||||
}
|
||||
serverActionLastTime.Set(gtime.TimestampMilli())
|
||||
return nil
|
||||
|
||||
@ -9,8 +9,8 @@ package ghttp
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"github.com/gogf/gf/os/gproc"
|
||||
"github.com/gogf/gf/os/gres"
|
||||
"github.com/gogf/gf/text/gstr"
|
||||
@ -122,7 +122,7 @@ func (s *gracefulServer) ListenAndServeTLS(certFile, keyFile string, tlsConfig .
|
||||
|
||||
}
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf(`open cert file "%s","%s" failed: %s`, certFile, keyFile, err.Error()))
|
||||
return gerror.Newf(`open cert file "%s","%s" failed: %s`, certFile, keyFile, err.Error())
|
||||
}
|
||||
ln, err := s.getNetListener()
|
||||
if err != nil {
|
||||
|
||||
@ -7,9 +7,9 @@
|
||||
package ghttp
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/container/gtype"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/debug/gdebug"
|
||||
@ -53,7 +53,7 @@ func (s *Server) parsePattern(pattern string) (domain, method, path string, err
|
||||
}
|
||||
}
|
||||
if path == "" {
|
||||
err = errors.New("invalid pattern: URI should not be empty")
|
||||
err = gerror.New("invalid pattern: URI should not be empty")
|
||||
}
|
||||
if path != "/" {
|
||||
path = strings.TrimRight(path, "/")
|
||||
|
||||
@ -9,8 +9,7 @@ package client
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"github.com/gogf/gf/internal/intlog"
|
||||
"github.com/gogf/gf/internal/json"
|
||||
"github.com/gogf/gf/internal/utils"
|
||||
@ -189,7 +188,7 @@ func (c *Client) prepareRequest(method, url string, data ...interface{}) (req *h
|
||||
if len(array[1]) > 6 && strings.Compare(array[1][0:6], "@file:") == 0 {
|
||||
path := array[1][6:]
|
||||
if !gfile.Exists(path) {
|
||||
return nil, errors.New(fmt.Sprintf(`"%s" does not exist`, path))
|
||||
return nil, gerror.Newf(`"%s" does not exist`, path)
|
||||
}
|
||||
if file, err := writer.CreateFormFile(array[0], gfile.Basename(path)); err == nil {
|
||||
if f, err := os.Open(path); err == nil {
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
package gipv4
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -38,7 +38,7 @@ func GetIntranetIp() (ip string, err error) {
|
||||
return "", err
|
||||
}
|
||||
if len(ips) == 0 {
|
||||
return "", errors.New("no intranet ip found")
|
||||
return "", gerror.New("no intranet ip found")
|
||||
}
|
||||
return ips[0], nil
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ package gtcp
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"net"
|
||||
"sync"
|
||||
|
||||
@ -116,7 +116,7 @@ func (s *Server) Close() error {
|
||||
// Run starts running the TCP Server.
|
||||
func (s *Server) Run() (err error) {
|
||||
if s.handler == nil {
|
||||
err = errors.New("start running failed: socket handler not defined")
|
||||
err = gerror.New("start running failed: socket handler not defined")
|
||||
glog.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
package gudp
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"net"
|
||||
|
||||
"github.com/gogf/gf/container/gmap"
|
||||
@ -78,7 +78,7 @@ func (s *Server) Close() error {
|
||||
// Run starts listening UDP connection.
|
||||
func (s *Server) Run() error {
|
||||
if s.handler == nil {
|
||||
err := errors.New("start running failed: socket handler not defined")
|
||||
err := gerror.New("start running failed: socket handler not defined")
|
||||
glog.Error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -9,7 +9,6 @@ package gcfg
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/container/garray"
|
||||
"github.com/gogf/gf/container/gmap"
|
||||
@ -143,7 +142,7 @@ func (c *Config) SetPath(path string) error {
|
||||
} else {
|
||||
buffer.WriteString(fmt.Sprintf(`[gcfg] SetPath failed: path "%s" does not exist`, path))
|
||||
}
|
||||
err := errors.New(buffer.String())
|
||||
err := gerror.New(buffer.String())
|
||||
if errorPrint() {
|
||||
glog.Error(err)
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
package gcfg
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/encoding/gjson"
|
||||
@ -295,7 +295,7 @@ func (c *Config) GetStruct(pattern string, pointer interface{}, mapping ...map[s
|
||||
if j := c.getJson(); j != nil {
|
||||
return j.GetStruct(pattern, pointer, mapping...)
|
||||
}
|
||||
return errors.New("configuration not found")
|
||||
return gerror.New("configuration not found")
|
||||
}
|
||||
|
||||
// GetStructs converts any slice to given struct slice.
|
||||
@ -303,7 +303,7 @@ func (c *Config) GetStructs(pattern string, pointer interface{}, mapping ...map[
|
||||
if j := c.getJson(); j != nil {
|
||||
return j.GetStructs(pattern, pointer, mapping...)
|
||||
}
|
||||
return errors.New("configuration not found")
|
||||
return gerror.New("configuration not found")
|
||||
}
|
||||
|
||||
// GetMapToMap retrieves the value by specified `pattern` and converts it to specified map variable.
|
||||
@ -312,7 +312,7 @@ func (c *Config) GetMapToMap(pattern string, pointer interface{}, mapping ...map
|
||||
if j := c.getJson(); j != nil {
|
||||
return j.GetMapToMap(pattern, pointer, mapping...)
|
||||
}
|
||||
return errors.New("configuration not found")
|
||||
return gerror.New("configuration not found")
|
||||
}
|
||||
|
||||
// GetMapToMaps retrieves the value by specified `pattern` and converts it to specified map slice
|
||||
@ -322,7 +322,7 @@ func (c *Config) GetMapToMaps(pattern string, pointer interface{}, mapping ...ma
|
||||
if j := c.getJson(); j != nil {
|
||||
return j.GetMapToMaps(pattern, pointer, mapping...)
|
||||
}
|
||||
return errors.New("configuration not found")
|
||||
return gerror.New("configuration not found")
|
||||
}
|
||||
|
||||
// GetMapToMapsDeep retrieves the value by specified `pattern` and converts it to specified map slice
|
||||
@ -332,7 +332,7 @@ func (c *Config) GetMapToMapsDeep(pattern string, pointer interface{}, mapping .
|
||||
if j := c.getJson(); j != nil {
|
||||
return j.GetMapToMapsDeep(pattern, pointer, mapping...)
|
||||
}
|
||||
return errors.New("configuration not found")
|
||||
return gerror.New("configuration not found")
|
||||
}
|
||||
|
||||
// Map converts current Json object to map[string]interface{}. It returns nil if fails.
|
||||
@ -358,7 +358,7 @@ func (c *Config) Struct(pointer interface{}, mapping ...map[string]string) error
|
||||
if j := c.getJson(); j != nil {
|
||||
return j.Struct(pointer, mapping...)
|
||||
}
|
||||
return errors.New("configuration not found")
|
||||
return gerror.New("configuration not found")
|
||||
}
|
||||
|
||||
// Structs converts current Json object to specified object slice.
|
||||
@ -367,7 +367,7 @@ func (c *Config) Structs(pointer interface{}, mapping ...map[string]string) erro
|
||||
if j := c.getJson(); j != nil {
|
||||
return j.Structs(pointer, mapping...)
|
||||
}
|
||||
return errors.New("configuration not found")
|
||||
return gerror.New("configuration not found")
|
||||
}
|
||||
|
||||
// MapToMap converts current Json object to specified map variable.
|
||||
@ -376,7 +376,7 @@ func (c *Config) MapToMap(pointer interface{}, mapping ...map[string]string) err
|
||||
if j := c.getJson(); j != nil {
|
||||
return j.MapToMap(pointer, mapping...)
|
||||
}
|
||||
return errors.New("configuration not found")
|
||||
return gerror.New("configuration not found")
|
||||
}
|
||||
|
||||
// MapToMaps converts current Json object to specified map variable slice.
|
||||
@ -385,7 +385,7 @@ func (c *Config) MapToMaps(pointer interface{}, mapping ...map[string]string) er
|
||||
if j := c.getJson(); j != nil {
|
||||
return j.MapToMaps(pointer, mapping...)
|
||||
}
|
||||
return errors.New("configuration not found")
|
||||
return gerror.New("configuration not found")
|
||||
}
|
||||
|
||||
// Clear removes all parsed configuration files content cache,
|
||||
|
||||
@ -8,13 +8,13 @@
|
||||
package gcmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
)
|
||||
|
||||
// BindHandle registers callback function <f> with <cmd>.
|
||||
func BindHandle(cmd string, f func()) error {
|
||||
if _, ok := defaultCommandFuncMap[cmd]; ok {
|
||||
return errors.New("duplicated handle for command:" + cmd)
|
||||
return gerror.New("duplicated handle for command:" + cmd)
|
||||
} else {
|
||||
defaultCommandFuncMap[cmd] = f
|
||||
}
|
||||
@ -37,7 +37,7 @@ func RunHandle(cmd string) error {
|
||||
if handle, ok := defaultCommandFuncMap[cmd]; ok {
|
||||
handle()
|
||||
} else {
|
||||
return errors.New("no handle found for command:" + cmd)
|
||||
return gerror.New("no handle found for command:" + cmd)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -49,10 +49,10 @@ func AutoRun() error {
|
||||
if handle, ok := defaultCommandFuncMap[cmd]; ok {
|
||||
handle()
|
||||
} else {
|
||||
return errors.New("no handle found for command:" + cmd)
|
||||
return gerror.New("no handle found for command:" + cmd)
|
||||
}
|
||||
} else {
|
||||
return errors.New("no command found")
|
||||
return gerror.New("no command found")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -8,15 +8,13 @@
|
||||
package gcmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"github.com/gogf/gf/internal/json"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/text/gstr"
|
||||
|
||||
"errors"
|
||||
|
||||
"github.com/gogf/gf/container/gvar"
|
||||
|
||||
"github.com/gogf/gf/text/gregex"
|
||||
@ -96,7 +94,7 @@ func ParseWithArgs(args []string, supportedOptions map[string]bool, strict ...bo
|
||||
i++
|
||||
continue
|
||||
} else if parser.strict {
|
||||
return nil, errors.New(fmt.Sprintf(`invalid option '%s'`, args[i]))
|
||||
return nil, gerror.Newf(`invalid option '%s'`, args[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,20 +8,20 @@
|
||||
package gcmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
)
|
||||
|
||||
// BindHandle registers callback function <f> with <cmd>.
|
||||
func (p *Parser) BindHandle(cmd string, f func()) error {
|
||||
if _, ok := p.commandFuncMap[cmd]; ok {
|
||||
return errors.New("duplicated handle for command:" + cmd)
|
||||
return gerror.New("duplicated handle for command:" + cmd)
|
||||
} else {
|
||||
p.commandFuncMap[cmd] = f
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// BindHandle registers callback function with map <m>.
|
||||
// BindHandleMap registers callback function with map <m>.
|
||||
func (p *Parser) BindHandleMap(m map[string]func()) error {
|
||||
var err error
|
||||
for k, v := range m {
|
||||
@ -37,7 +37,7 @@ func (p *Parser) RunHandle(cmd string) error {
|
||||
if handle, ok := p.commandFuncMap[cmd]; ok {
|
||||
handle()
|
||||
} else {
|
||||
return errors.New("no handle found for command:" + cmd)
|
||||
return gerror.New("no handle found for command:" + cmd)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -49,10 +49,10 @@ func (p *Parser) AutoRun() error {
|
||||
if handle, ok := p.commandFuncMap[cmd]; ok {
|
||||
handle()
|
||||
} else {
|
||||
return errors.New("no handle found for command:" + cmd)
|
||||
return gerror.New("no handle found for command:" + cmd)
|
||||
}
|
||||
} else {
|
||||
return errors.New("no command found")
|
||||
return gerror.New("no command found")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -7,8 +7,7 @@
|
||||
package gcron
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/container/garray"
|
||||
@ -63,7 +62,7 @@ func (c *Cron) GetLogLevel() int {
|
||||
func (c *Cron) Add(pattern string, job func(), name ...string) (*Entry, error) {
|
||||
if len(name) > 0 {
|
||||
if c.Search(name[0]) != nil {
|
||||
return nil, errors.New(fmt.Sprintf(`cron job "%s" already exists`, name[0]))
|
||||
return nil, gerror.Newf(`cron job "%s" already exists`, name[0])
|
||||
}
|
||||
}
|
||||
return c.addEntry(pattern, job, false, name...)
|
||||
|
||||
@ -7,8 +7,7 @@
|
||||
package gcron
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"github.com/gogf/gf/os/gtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -91,7 +90,7 @@ func newSchedule(pattern string) (*cronSchedule, error) {
|
||||
}, nil
|
||||
}
|
||||
} else {
|
||||
return nil, errors.New(fmt.Sprintf(`invalid pattern: "%s"`, pattern))
|
||||
return nil, gerror.Newf(`invalid pattern: "%s"`, pattern)
|
||||
}
|
||||
}
|
||||
// Handle the common cron pattern, like:
|
||||
@ -140,7 +139,7 @@ func newSchedule(pattern string) (*cronSchedule, error) {
|
||||
}
|
||||
return schedule, nil
|
||||
} else {
|
||||
return nil, errors.New(fmt.Sprintf(`invalid pattern: "%s"`, pattern))
|
||||
return nil, gerror.Newf(`invalid pattern: "%s"`, pattern)
|
||||
}
|
||||
}
|
||||
|
||||
@ -157,7 +156,7 @@ func parseItem(item string, min int, max int, allowQuestionMark bool) (map[int]s
|
||||
intervalArray := strings.Split(item, "/")
|
||||
if len(intervalArray) == 2 {
|
||||
if i, err := strconv.Atoi(intervalArray[1]); err != nil {
|
||||
return nil, errors.New(fmt.Sprintf(`invalid pattern item: "%s"`, item))
|
||||
return nil, gerror.Newf(`invalid pattern item: "%s"`, item)
|
||||
} else {
|
||||
interval = i
|
||||
}
|
||||
@ -179,7 +178,7 @@ func parseItem(item string, min int, max int, allowQuestionMark bool) (map[int]s
|
||||
// Eg: */5
|
||||
if rangeArray[0] != "*" {
|
||||
if i, err := parseItemValue(rangeArray[0], fieldType); err != nil {
|
||||
return nil, errors.New(fmt.Sprintf(`invalid pattern item: "%s"`, item))
|
||||
return nil, gerror.Newf(`invalid pattern item: "%s"`, item)
|
||||
} else {
|
||||
rangeMin = i
|
||||
rangeMax = i
|
||||
@ -187,7 +186,7 @@ func parseItem(item string, min int, max int, allowQuestionMark bool) (map[int]s
|
||||
}
|
||||
if len(rangeArray) == 2 {
|
||||
if i, err := parseItemValue(rangeArray[1], fieldType); err != nil {
|
||||
return nil, errors.New(fmt.Sprintf(`invalid pattern item: "%s"`, item))
|
||||
return nil, gerror.Newf(`invalid pattern item: "%s"`, item)
|
||||
} else {
|
||||
rangeMax = i
|
||||
}
|
||||
@ -221,7 +220,7 @@ func parseItemValue(value string, fieldType byte) (int, error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0, errors.New(fmt.Sprintf(`invalid pattern value: "%s"`, value))
|
||||
return 0, gerror.Newf(`invalid pattern value: "%s"`, value)
|
||||
}
|
||||
|
||||
// meet checks if the given time <t> meets the runnable point for the job.
|
||||
|
||||
@ -9,9 +9,8 @@ package gfsnotify
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/container/gset"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"github.com/gogf/gf/internal/intlog"
|
||||
"sync"
|
||||
"time"
|
||||
@ -140,7 +139,7 @@ func RemoveCallback(callbackId int) error {
|
||||
callback = r.(*Callback)
|
||||
}
|
||||
if callback == nil {
|
||||
return errors.New(fmt.Sprintf(`callback for id %d not found`, callbackId))
|
||||
return gerror.Newf(`callback for id %d not found`, callbackId)
|
||||
}
|
||||
w.RemoveCallback(callbackId)
|
||||
return nil
|
||||
|
||||
@ -8,8 +8,7 @@ package gfsnotify
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"github.com/gogf/gf/internal/intlog"
|
||||
|
||||
"github.com/gogf/gf/container/glist"
|
||||
@ -66,7 +65,7 @@ func (w *Watcher) AddOnce(name, path string, callbackFunc func(event *Event), re
|
||||
func (w *Watcher) addWithCallbackFunc(name, path string, callbackFunc func(event *Event), recursive ...bool) (callback *Callback, err error) {
|
||||
// Check and convert the given path to absolute path.
|
||||
if t := fileRealPath(path); t == "" {
|
||||
return nil, errors.New(fmt.Sprintf(`"%s" does not exist`, path))
|
||||
return nil, gerror.Newf(`"%s" does not exist`, path)
|
||||
} else {
|
||||
path = t
|
||||
}
|
||||
|
||||
@ -7,8 +7,6 @@
|
||||
package glog
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
"time"
|
||||
@ -82,7 +80,7 @@ func (l *Logger) SetConfig(config Config) error {
|
||||
// SetConfigWithMap set configurations with map for the logger.
|
||||
func (l *Logger) SetConfigWithMap(m map[string]interface{}) error {
|
||||
if m == nil || len(m) == 0 {
|
||||
return errors.New("configuration cannot be empty")
|
||||
return gerror.New("configuration cannot be empty")
|
||||
}
|
||||
// The m now is a shallow copy of m.
|
||||
// A little tricky, isn't it?
|
||||
@ -93,7 +91,7 @@ func (l *Logger) SetConfigWithMap(m map[string]interface{}) error {
|
||||
if level, ok := levelStringMap[strings.ToUpper(gconv.String(levelValue))]; ok {
|
||||
m[levelKey] = level
|
||||
} else {
|
||||
return errors.New(fmt.Sprintf(`invalid level string: %v`, levelValue))
|
||||
return gerror.Newf(`invalid level string: %v`, levelValue)
|
||||
}
|
||||
}
|
||||
// Change string configuration to int value for file rotation size.
|
||||
@ -101,7 +99,7 @@ func (l *Logger) SetConfigWithMap(m map[string]interface{}) error {
|
||||
if rotateSizeValue != nil {
|
||||
m[rotateSizeKey] = gfile.StrToSize(gconv.String(rotateSizeValue))
|
||||
if m[rotateSizeKey] == -1 {
|
||||
return errors.New(fmt.Sprintf(`invalid rotate size: %v`, rotateSizeValue))
|
||||
return gerror.Newf(`invalid rotate size: %v`, rotateSizeValue)
|
||||
}
|
||||
}
|
||||
if err := gconv.Struct(m, &l.config); err != nil {
|
||||
@ -206,7 +204,7 @@ func (l *Logger) GetWriter() io.Writer {
|
||||
// SetPath sets the directory path for file logging.
|
||||
func (l *Logger) SetPath(path string) error {
|
||||
if path == "" {
|
||||
return errors.New("logging path is empty")
|
||||
return gerror.New("logging path is empty")
|
||||
}
|
||||
if !gfile.Exists(path) {
|
||||
if err := gfile.Mkdir(path); err != nil {
|
||||
|
||||
@ -7,8 +7,7 @@
|
||||
package glog
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -78,7 +77,7 @@ func (l *Logger) SetLevelStr(levelStr string) error {
|
||||
if level, ok := levelStringMap[strings.ToUpper(levelStr)]; ok {
|
||||
l.config.Level = level
|
||||
} else {
|
||||
return errors.New(fmt.Sprintf(`invalid level string: %s`, levelStr))
|
||||
return gerror.Newf(`invalid level string: %s`, levelStr)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -7,9 +7,9 @@
|
||||
package gproc
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/container/gmap"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"github.com/gogf/gf/net/gtcp"
|
||||
"github.com/gogf/gf/os/gfile"
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
@ -65,7 +65,7 @@ func getConnByPid(pid int) (*gtcp.PoolConn, error) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nil, errors.New(fmt.Sprintf("could not find port for pid: %d", pid))
|
||||
return nil, gerror.Newf("could not find port for pid: %d", pid)
|
||||
}
|
||||
|
||||
// getPortByPid returns the listening port for specified pid.
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
package gproc
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"github.com/gogf/gf/internal/json"
|
||||
"github.com/gogf/gf/net/gtcp"
|
||||
"io"
|
||||
@ -46,7 +46,7 @@ func Send(pid int, data []byte, group ...string) error {
|
||||
err = json.UnmarshalUseNumber(result, response)
|
||||
if err == nil {
|
||||
if response.Code != 1 {
|
||||
err = errors.New(response.Message)
|
||||
err = gerror.New(response.Message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,8 +8,8 @@ package gproc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"github.com/gogf/gf/internal/intlog"
|
||||
"os"
|
||||
"os/exec"
|
||||
@ -101,7 +101,7 @@ func (p *Process) Send(data []byte) error {
|
||||
if p.Process != nil {
|
||||
return Send(p.Process.Pid, data)
|
||||
}
|
||||
return errors.New("invalid process")
|
||||
return gerror.New("invalid process")
|
||||
}
|
||||
|
||||
// Release releases any resources associated with the Process p,
|
||||
|
||||
@ -8,8 +8,7 @@
|
||||
package grpool
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
|
||||
"github.com/gogf/gf/container/glist"
|
||||
"github.com/gogf/gf/container/gtype"
|
||||
@ -70,7 +69,7 @@ func Jobs() int {
|
||||
// The job will be executed asynchronously.
|
||||
func (p *Pool) Add(f func()) error {
|
||||
for p.closed.Val() {
|
||||
return errors.New("pool closed")
|
||||
return gerror.New("pool closed")
|
||||
}
|
||||
p.list.PushFront(f)
|
||||
// Check whether fork new goroutine or not.
|
||||
@ -99,7 +98,7 @@ func (p *Pool) AddWithRecover(userFunc func(), recoverFunc ...func(err error)) e
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if len(recoverFunc) > 0 && recoverFunc[0] != nil {
|
||||
recoverFunc[0](errors.New(fmt.Sprintf(`%v`, err)))
|
||||
recoverFunc[0](gerror.Newf(`%v`, err))
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
@ -8,7 +8,7 @@ package gsession
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"github.com/gogf/gf/internal/intlog"
|
||||
"time"
|
||||
|
||||
@ -182,7 +182,7 @@ func (s *Session) Id() string {
|
||||
// It returns error if it is called after session starts.
|
||||
func (s *Session) SetId(id string) error {
|
||||
if s.start {
|
||||
return errors.New("session already started")
|
||||
return gerror.New("session already started")
|
||||
}
|
||||
s.id = id
|
||||
return nil
|
||||
@ -192,7 +192,7 @@ func (s *Session) SetId(id string) error {
|
||||
// It returns error if it is called after session starts.
|
||||
func (s *Session) SetIdFunc(f func(ttl time.Duration) string) error {
|
||||
if s.start {
|
||||
return errors.New("session already started")
|
||||
return gerror.New("session already started")
|
||||
}
|
||||
s.idFunc = f
|
||||
return nil
|
||||
|
||||
@ -13,8 +13,7 @@ package gspath
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"github.com/gogf/gf/internal/intlog"
|
||||
"os"
|
||||
"sort"
|
||||
@ -104,7 +103,7 @@ func (sp *SPath) Set(path string) (realPath string, err error) {
|
||||
}
|
||||
}
|
||||
if realPath == "" {
|
||||
return realPath, errors.New(fmt.Sprintf(`path "%s" does not exist`, path))
|
||||
return realPath, gerror.Newf(`path "%s" does not exist`, path)
|
||||
}
|
||||
// The set path must be a directory.
|
||||
if gfile.IsDir(realPath) {
|
||||
@ -124,7 +123,7 @@ func (sp *SPath) Set(path string) (realPath string, err error) {
|
||||
sp.addMonitorByPath(realPath)
|
||||
return realPath, nil
|
||||
} else {
|
||||
return "", errors.New(path + " should be a folder")
|
||||
return "", gerror.New(path + " should be a folder")
|
||||
}
|
||||
}
|
||||
|
||||
@ -139,7 +138,7 @@ func (sp *SPath) Add(path string) (realPath string, err error) {
|
||||
}
|
||||
}
|
||||
if realPath == "" {
|
||||
return realPath, errors.New(fmt.Sprintf(`path "%s" does not exist`, path))
|
||||
return realPath, gerror.Newf(`path "%s" does not exist`, path)
|
||||
}
|
||||
// The added path must be a directory.
|
||||
if gfile.IsDir(realPath) {
|
||||
@ -153,7 +152,7 @@ func (sp *SPath) Add(path string) (realPath string, err error) {
|
||||
}
|
||||
return realPath, nil
|
||||
} else {
|
||||
return "", errors.New(path + " should be a folder")
|
||||
return "", gerror.New(path + " should be a folder")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -8,8 +8,7 @@ package gview
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"github.com/gogf/gf/i18n/gi18n"
|
||||
"github.com/gogf/gf/internal/intlog"
|
||||
"github.com/gogf/gf/os/gfile"
|
||||
@ -75,7 +74,7 @@ func (view *View) SetConfig(config Config) error {
|
||||
// SetConfigWithMap set configurations with map for the view.
|
||||
func (view *View) SetConfigWithMap(m map[string]interface{}) error {
|
||||
if m == nil || len(m) == 0 {
|
||||
return errors.New("configuration cannot be empty")
|
||||
return gerror.New("configuration cannot be empty")
|
||||
}
|
||||
// The m now is a shallow copy of m.
|
||||
// Any changes to m does not affect the original one.
|
||||
@ -124,7 +123,7 @@ func (view *View) SetPath(path string) error {
|
||||
}
|
||||
// Path not exist.
|
||||
if realPath == "" {
|
||||
err := errors.New(fmt.Sprintf(`[gview] SetPath failed: path "%s" does not exist`, path))
|
||||
err := gerror.Newf(`[gview] SetPath failed: path "%s" does not exist`, path)
|
||||
if errorPrint() {
|
||||
glog.Error(err)
|
||||
}
|
||||
@ -132,7 +131,7 @@ func (view *View) SetPath(path string) error {
|
||||
}
|
||||
// Should be a directory.
|
||||
if !isDir {
|
||||
err := errors.New(fmt.Sprintf(`[gview] SetPath failed: path "%s" should be directory type`, path))
|
||||
err := gerror.Newf(`[gview] SetPath failed: path "%s" should be directory type`, path)
|
||||
if errorPrint() {
|
||||
glog.Error(err)
|
||||
}
|
||||
@ -178,7 +177,7 @@ func (view *View) AddPath(path string) error {
|
||||
}
|
||||
// Path not exist.
|
||||
if realPath == "" {
|
||||
err := errors.New(fmt.Sprintf(`[gview] AddPath failed: path "%s" does not exist`, path))
|
||||
err := gerror.Newf(`[gview] AddPath failed: path "%s" does not exist`, path)
|
||||
if errorPrint() {
|
||||
glog.Error(err)
|
||||
}
|
||||
@ -186,7 +185,7 @@ func (view *View) AddPath(path string) error {
|
||||
}
|
||||
// realPath should be type of folder.
|
||||
if !isDir {
|
||||
err := errors.New(fmt.Sprintf(`[gview] AddPath failed: path "%s" should be directory type`, path))
|
||||
err := gerror.Newf(`[gview] AddPath failed: path "%s" should be directory type`, path)
|
||||
if errorPrint() {
|
||||
glog.Error(err)
|
||||
}
|
||||
|
||||
@ -9,7 +9,6 @@ package gview
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/encoding/ghash"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
@ -377,7 +376,7 @@ func (view *View) searchFile(file string) (path string, folder string, resource
|
||||
if errorPrint() {
|
||||
glog.Error(buffer.String())
|
||||
}
|
||||
err = errors.New(fmt.Sprintf(`template file "%s" not found`, file))
|
||||
err = gerror.Newf(`template file "%s" not found`, file)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@ -7,9 +7,9 @@
|
||||
package gconv_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/gogf/gf/crypto/gcrc32"
|
||||
"github.com/gogf/gf/encoding/gbinary"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"github.com/gogf/gf/frame/g"
|
||||
"github.com/gogf/gf/os/gtime"
|
||||
"github.com/gogf/gf/test/gtest"
|
||||
@ -83,16 +83,16 @@ func (p *Pkg) Marshal() []byte {
|
||||
func (p *Pkg) UnmarshalValue(v interface{}) error {
|
||||
b := gconv.Bytes(v)
|
||||
if len(b) < 6 {
|
||||
return errors.New("invalid package length")
|
||||
return gerror.New("invalid package length")
|
||||
}
|
||||
p.Length = gbinary.DecodeToUint16(b[:2])
|
||||
if len(b) < int(p.Length) {
|
||||
return errors.New("invalid data length")
|
||||
return gerror.New("invalid data length")
|
||||
}
|
||||
p.Crc32 = gbinary.DecodeToUint32(b[2:6])
|
||||
p.Data = b[6:]
|
||||
if gcrc32.Encrypt(p.Data) != p.Crc32 {
|
||||
return errors.New("crc32 validation failed")
|
||||
return gerror.New("crc32 validation failed")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
package gvalid
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@ -175,7 +175,7 @@ func (v *Validator) doCheckBuildInRules(
|
||||
"max-length",
|
||||
"size":
|
||||
if msg := v.checkLength(valueStr, ruleKey, rulePattern, customMsgMap); msg != "" {
|
||||
return match, errors.New(msg)
|
||||
return match, gerror.New(msg)
|
||||
} else {
|
||||
match = true
|
||||
}
|
||||
@ -186,7 +186,7 @@ func (v *Validator) doCheckBuildInRules(
|
||||
"max",
|
||||
"between":
|
||||
if msg := v.checkRange(valueStr, ruleKey, rulePattern, customMsgMap); msg != "" {
|
||||
return match, errors.New(msg)
|
||||
return match, gerror.New(msg)
|
||||
} else {
|
||||
match = true
|
||||
}
|
||||
@ -222,7 +222,7 @@ func (v *Validator) doCheckBuildInRules(
|
||||
var msg string
|
||||
msg = v.getErrorMessageByRule(ruleKey, customMsgMap)
|
||||
msg = strings.Replace(msg, ":format", rulePattern, -1)
|
||||
return match, errors.New(msg)
|
||||
return match, gerror.New(msg)
|
||||
}
|
||||
|
||||
// Values of two fields should be equal as string.
|
||||
@ -237,7 +237,7 @@ func (v *Validator) doCheckBuildInRules(
|
||||
var msg string
|
||||
msg = v.getErrorMessageByRule(ruleKey, customMsgMap)
|
||||
msg = strings.Replace(msg, ":field", rulePattern, -1)
|
||||
return match, errors.New(msg)
|
||||
return match, gerror.New(msg)
|
||||
}
|
||||
|
||||
// Values of two fields should not be equal as string.
|
||||
@ -253,7 +253,7 @@ func (v *Validator) doCheckBuildInRules(
|
||||
var msg string
|
||||
msg = v.getErrorMessageByRule(ruleKey, customMsgMap)
|
||||
msg = strings.Replace(msg, ":field", rulePattern, -1)
|
||||
return match, errors.New(msg)
|
||||
return match, gerror.New(msg)
|
||||
}
|
||||
|
||||
// Field value should be in range of.
|
||||
@ -436,7 +436,7 @@ func (v *Validator) doCheckBuildInRules(
|
||||
match = gregex.IsMatchString(`^([0-9A-Fa-f]{2}[\-:]){5}[0-9A-Fa-f]{2}$`, valueStr)
|
||||
|
||||
default:
|
||||
return match, errors.New("Invalid rule name: " + ruleKey)
|
||||
return match, gerror.New("Invalid rule name: " + ruleKey)
|
||||
}
|
||||
return match, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user