style(go-pkg): rename package

This commit is contained in:
pyihe
2022-03-10 11:47:35 +08:00
parent 360a014dde
commit ab921f7824
51 changed files with 100 additions and 100 deletions

View File

@@ -1,4 +1,4 @@
package bytepkg package bytes
import ( import (
"unsafe" "unsafe"

View File

@@ -1,4 +1,4 @@
package certpkg package certs
import ( import (
"crypto/tls" "crypto/tls"

View File

@@ -1,4 +1,4 @@
package clonepkg package clones
import "reflect" import "reflect"

View File

@@ -1,4 +1,4 @@
package cryptopkg package cryptos
import ( import (
"encoding/base64" "encoding/base64"

View File

@@ -1,4 +1,4 @@
package errpkg package errors
type Error struct { type Error struct {
err string err string

View File

@@ -1,4 +1,4 @@
package filepkg package files
import "os" import "os"

View File

@@ -1,4 +1,4 @@
package httppkg package https
import ( import (
"io" "io"
@@ -6,13 +6,13 @@ import (
"net/http" "net/http"
"strings" "strings"
"github.com/pyihe/go-pkg/errpkg" "github.com/pyihe/go-pkg/errors"
"github.com/pyihe/go-pkg/serialize" "github.com/pyihe/go-pkg/serialize"
) )
var ( var (
ErrInvalidUrl = errpkg.New("url must start with 'http'") ErrInvalidUrl = errors.New("url must start with 'http'")
ErrInvalidEncoder = errpkg.New("invalid encoder") ErrInvalidEncoder = errors.New("invalid encoder")
) )
// Get 发起http get请求 // Get 发起http get请求

View File

@@ -1,4 +1,4 @@
package httppkg package https
import ( import (
"crypto/tls" "crypto/tls"

View File

@@ -1,9 +1,9 @@
package listpkg package lists
import ( import (
"sync" "sync"
"github.com/pyihe/go-pkg/mathpkg" "github.com/pyihe/go-pkg/maths"
) )
// ArrayList 切片实现的队列 // ArrayList 切片实现的队列
@@ -41,7 +41,7 @@ func (array *ArrayList) LPush(elements ...interface{}) (n int) {
func (array *ArrayList) LPop(n int) (data []interface{}) { func (array *ArrayList) LPop(n int) (data []interface{}) {
array.mu.Lock() array.mu.Lock()
if count := len(array.data); count > 0 { if count := len(array.data); count > 0 {
n = mathpkg.MinInt(n, count) n = maths.MinInt(n, count)
data, array.data = array.data[:n], array.data[n:] data, array.data = array.data[:n], array.data[n:]
} }
array.mu.Unlock() array.mu.Unlock()
@@ -101,7 +101,7 @@ func (array *ArrayList) RPush(elements ...interface{}) (n int) {
func (array *ArrayList) RPop(n int) (data []interface{}) { func (array *ArrayList) RPop(n int) (data []interface{}) {
array.mu.Lock() array.mu.Lock()
if count := len(array.data); count > 0 { if count := len(array.data); count > 0 {
n = mathpkg.MinInt(n, count) n = maths.MinInt(n, count)
data, array.data = array.data[count-n:], array.data[:count-n] data, array.data = array.data[count-n:], array.data[:count-n]
// 需要对结果进行倒序 // 需要对结果进行倒序
for i := 0; i < n/2; i++ { for i := 0; i < n/2; i++ {

View File

@@ -1,10 +1,10 @@
package listpkg package lists
import ( import (
"container/list" "container/list"
"sync" "sync"
"github.com/pyihe/go-pkg/mathpkg" "github.com/pyihe/go-pkg/maths"
) )
type HashList struct { type HashList struct {
@@ -327,8 +327,8 @@ func (hl *HashList) pop(front bool, n int, key interface{}) (elements []interfac
} }
func handleIndex(length, start, end int) (int, int) { func handleIndex(length, start, end int) (int, int) {
start = mathpkg.MaxInt(mathpkg.MinInt(start, length), 0) start = maths.MaxInt(maths.MinInt(start, length), 0)
end = mathpkg.MaxInt(mathpkg.MinInt(end, length), 0) end = maths.MaxInt(maths.MinInt(end, length), 0)
return start, end return start, end
} }

View File

@@ -1,3 +1,3 @@
package listpkg package lists
// 链表实现的队列, container/list内置的List // 链表实现的队列, container/list内置的List

View File

@@ -1,3 +1,3 @@
package listpkg package lists
// 优先级队列 // 优先级队列

View File

@@ -1,4 +1,4 @@
package logpkg package logs
var ( var (
logger Logger logger Logger

View File

@@ -1,4 +1,4 @@
package logpkg package logs
// LogOption 日志配置项 // LogOption 日志配置项
type LogOption func(zl *zapLogger) type LogOption func(zl *zapLogger)

View File

@@ -1,4 +1,4 @@
package logpkg package logs
import ( import (
"io" "io"
@@ -6,7 +6,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/pyihe/go-pkg/netpkg" "github.com/pyihe/go-pkg/nets"
rotatelogs "github.com/lestrrat-go/file-rotatelogs" rotatelogs "github.com/lestrrat-go/file-rotatelogs"
"go.uber.org/zap" "go.uber.org/zap"
@@ -57,7 +57,7 @@ func newZapLogger(opts ...LogOption) (Logger, error) {
encoder := getJSONEncoder() encoder := getJSONEncoder()
op := zap.Fields(zap.String("ip", netpkg.GetLocalIP()), zap.String("app", zlogger.name)) op := zap.Fields(zap.String("ip", nets.GetLocalIP()), zap.String("app", zlogger.name))
options = append(options, op) options = append(options, op)
allLevel := zap.LevelEnablerFunc(func(lv zapcore.Level) bool { allLevel := zap.LevelEnablerFunc(func(lv zapcore.Level) bool {

View File

@@ -1,4 +1,4 @@
package mappkg package maps
import "sync" import "sync"

View File

@@ -1,10 +1,10 @@
package mappkg package maps
import ( import (
"reflect" "reflect"
"strconv" "strconv"
"github.com/pyihe/go-pkg/errpkg" "github.com/pyihe/go-pkg/errors"
) )
type Param map[string]interface{} type Param map[string]interface{}
@@ -39,7 +39,7 @@ func (p Param) Range(fn func(key string, value interface{}) (breakOut bool)) {
func (p Param) GetString(key string) (string, error) { func (p Param) GetString(key string) (string, error) {
value, ok := p.Get(key) value, ok := p.Get(key)
if !ok { if !ok {
return "", errpkg.New("not exist key: " + key) return "", errors.New("not exist key: " + key)
} }
return reflect.ValueOf(value).String(), nil return reflect.ValueOf(value).String(), nil
} }
@@ -47,7 +47,7 @@ func (p Param) GetString(key string) (string, error) {
func (p Param) GetInt64(key string) (n int64, err error) { func (p Param) GetInt64(key string) (n int64, err error) {
value, ok := p.Get(key) value, ok := p.Get(key)
if !ok { if !ok {
return 0, errpkg.New("not exist key: " + key) return 0, errors.New("not exist key: " + key)
} }
t := reflect.TypeOf(value) t := reflect.TypeOf(value)
v := reflect.ValueOf(value) v := reflect.ValueOf(value)
@@ -65,7 +65,7 @@ func (p Param) GetInt64(key string) (n int64, err error) {
case reflect.Float32, reflect.Float64: case reflect.Float32, reflect.Float64:
n = int64(v.Float()) n = int64(v.Float())
default: default:
err = errpkg.New("unknown type: " + t.String()) err = errors.New("unknown type: " + t.String())
} }
return return
} }

View File

@@ -1,4 +1,4 @@
package mappkg package maps
import "sync" import "sync"

View File

@@ -1,4 +1,4 @@
package mathpkg package maths
func factorial(m int) (n int) { func factorial(m int) (n int) {
n = 1 n = 1

View File

@@ -1,4 +1,4 @@
package mathpkg package maths
func MaxInt(a, b int) int { func MaxInt(a, b int) int {
if a > b { if a > b {

View File

@@ -1,4 +1,4 @@
package monitorpkg package monitor
import ( import (
"os" "os"

View File

@@ -1,4 +1,4 @@
package monitorpkg package monitor
import ( import (
"errors" "errors"

View File

@@ -1,4 +1,4 @@
package netpkg package nets
import ( import (
"net" "net"

View File

@@ -1,4 +1,4 @@
package pointerpkg package ptrs
/* /*
返回各种基本数据类型的指针 返回各种基本数据类型的指针

View File

@@ -1,10 +1,10 @@
package randpkg package rands
import ( import (
"math/rand" "math/rand"
"time" "time"
"github.com/pyihe/go-pkg/bytepkg" "github.com/pyihe/go-pkg/bytes"
) )
const ( const (
@@ -74,7 +74,7 @@ func String(n int) string {
cache >>= letterIdxBits cache >>= letterIdxBits
remain-- remain--
} }
return bytepkg.String(b) return bytes.String(b)
} }
// ShuffleBytes shuffle 随机算法 // ShuffleBytes shuffle 随机算法

View File

@@ -1,16 +1,16 @@
package redispkg package rediss
import ( import (
"github.com/garyburd/redigo/redis" "github.com/garyburd/redigo/redis"
"github.com/pyihe/go-pkg/errpkg" "github.com/pyihe/go-pkg/errors"
"github.com/pyihe/go-pkg/serialize" "github.com/pyihe/go-pkg/serialize"
) )
var ( var (
ErrInvalidKey = errpkg.New("invalid key") ErrInvalidKey = errors.New("invalid key")
ErrInvalidEncoder = errpkg.New("not figure encoder") ErrInvalidEncoder = errors.New("not figure encoder")
ErrInvalidConn = errpkg.New("invalid redis conn") ErrInvalidConn = errors.New("invalid redis conn")
ErrInvalidParamNum = errpkg.New("invalid param num") ErrInvalidParamNum = errors.New("invalid param num")
) )
type myRedisConn struct { type myRedisConn struct {

View File

@@ -1,4 +1,4 @@
package redispkg package rediss
func (conn *myRedisConn) HGet(key string, field string) ([]byte, error) { func (conn *myRedisConn) HGet(key string, field string) ([]byte, error) {
value, err := conn.hGet(key, field) value, err := conn.hGet(key, field)

View File

@@ -1,4 +1,4 @@
package redispkg package rediss
func (conn *myRedisConn) RPush(key string, values ...interface{}) error { func (conn *myRedisConn) RPush(key string, values ...interface{}) error {
err := conn.rpush(key, values...) err := conn.rpush(key, values...)

View File

@@ -1,4 +1,4 @@
package redispkg package rediss
import ( import (
"fmt" "fmt"
@@ -105,7 +105,7 @@ func NewPool(opts ...InitOptions) (RedisPool, error) {
op(defaultPool) op(defaultPool)
} }
if defaultPool.addr == "" { if defaultPool.addr == "" {
return nil, fmt.Errorf("no redispkg address") return nil, fmt.Errorf("no rediss address")
} }
if defaultPool.db == 0 { if defaultPool.db == 0 {
defaultPool.db = 1 defaultPool.db = 1

View File

@@ -1,4 +1,4 @@
package redispkg package rediss
func (conn *myRedisConn) SADD(key string, members ...interface{}) error { func (conn *myRedisConn) SADD(key string, members ...interface{}) error {
err := conn.sAdd(key, members...) err := conn.sAdd(key, members...)

View File

@@ -1,4 +1,4 @@
package redispkg package rediss
func (conn *myRedisConn) GetKeys(pattern string) (keys []string, err error) { func (conn *myRedisConn) GetKeys(pattern string) (keys []string, err error) {
keys, err = conn.getKeys(pattern) keys, err = conn.getKeys(pattern)

View File

@@ -1,9 +1,9 @@
package slicepkg package slices
import ( import (
"fmt" "fmt"
"github.com/pyihe/go-pkg/sortpkg" "github.com/pyihe/go-pkg/sorts"
) )
type float32Slice []float32 type float32Slice []float32
@@ -38,7 +38,7 @@ func (f *float32Slice) Sort() {
if f == nil { if f == nil {
return return
} }
sortpkg.SortFloat32s(*f) sorts.SortFloat32s(*f)
} }
func (f *float32Slice) PushBack(x interface{}) (bool, int) { func (f *float32Slice) PushBack(x interface{}) (bool, int) {

View File

@@ -1,9 +1,9 @@
package slicepkg package slices
import ( import (
"fmt" "fmt"
"github.com/pyihe/go-pkg/sortpkg" "github.com/pyihe/go-pkg/sorts"
) )
type float64Slice []float64 type float64Slice []float64
@@ -38,7 +38,7 @@ func (f *float64Slice) Sort() {
if f == nil { if f == nil {
return return
} }
sortpkg.SortFloat64s(*f) sorts.SortFloat64s(*f)
} }
func (f *float64Slice) PushBack(x interface{}) (bool, int) { func (f *float64Slice) PushBack(x interface{}) (bool, int) {

View File

@@ -1,9 +1,9 @@
package slicepkg package slices
import ( import (
"fmt" "fmt"
"github.com/pyihe/go-pkg/sortpkg" "github.com/pyihe/go-pkg/sorts"
) )
type intSlice []int type intSlice []int
@@ -38,7 +38,7 @@ func (is *intSlice) Sort() {
if is == nil { if is == nil {
return return
} }
sortpkg.SortInts(*is) sorts.SortInts(*is)
} }
func (is *intSlice) PushBack(x interface{}) (bool, int) { func (is *intSlice) PushBack(x interface{}) (bool, int) {

View File

@@ -1,9 +1,9 @@
package slicepkg package slices
import ( import (
"fmt" "fmt"
"github.com/pyihe/go-pkg/sortpkg" "github.com/pyihe/go-pkg/sorts"
) )
type int16Slice []int16 type int16Slice []int16
@@ -38,7 +38,7 @@ func (i16 *int16Slice) Sort() {
if i16 == nil { if i16 == nil {
return return
} }
sortpkg.SortInt16s(*i16) sorts.SortInt16s(*i16)
} }
func (i16 *int16Slice) PushBack(x interface{}) (bool, int) { func (i16 *int16Slice) PushBack(x interface{}) (bool, int) {

View File

@@ -1,9 +1,9 @@
package slicepkg package slices
import ( import (
"fmt" "fmt"
"github.com/pyihe/go-pkg/sortpkg" "github.com/pyihe/go-pkg/sorts"
) )
type int32Slice []int32 type int32Slice []int32
@@ -38,7 +38,7 @@ func (i32 *int32Slice) Sort() {
if i32 == nil { if i32 == nil {
return return
} }
sortpkg.SortInt32s(*i32) sorts.SortInt32s(*i32)
} }
func (i32 *int32Slice) PushBack(x interface{}) (bool, int) { func (i32 *int32Slice) PushBack(x interface{}) (bool, int) {

View File

@@ -1,9 +1,9 @@
package slicepkg package slices
import ( import (
"fmt" "fmt"
"github.com/pyihe/go-pkg/sortpkg" "github.com/pyihe/go-pkg/sorts"
) )
type int64Slice []int64 type int64Slice []int64
@@ -38,7 +38,7 @@ func (i64 *int64Slice) Sort() {
if i64 == nil { if i64 == nil {
return return
} }
sortpkg.SortInt64s(*i64) sorts.SortInt64s(*i64)
} }
func (i64 *int64Slice) PushBack(x interface{}) (bool, int) { func (i64 *int64Slice) PushBack(x interface{}) (bool, int) {

View File

@@ -1,9 +1,9 @@
package slicepkg package slices
import ( import (
"fmt" "fmt"
"github.com/pyihe/go-pkg/sortpkg" "github.com/pyihe/go-pkg/sorts"
) )
type int8Slice []int8 type int8Slice []int8
@@ -38,7 +38,7 @@ func (i8 *int8Slice) Sort() {
if i8 == nil { if i8 == nil {
return return
} }
sortpkg.SortInt8s(*i8) sorts.SortInt8s(*i8)
} }
func (i8 *int8Slice) PushBack(x interface{}) (bool, int) { func (i8 *int8Slice) PushBack(x interface{}) (bool, int) {

View File

@@ -1,4 +1,4 @@
package slicepkg package slices
import ( import (
"fmt" "fmt"

View File

@@ -1,9 +1,9 @@
package slicepkg package slices
import ( import (
"fmt" "fmt"
"github.com/pyihe/go-pkg/sortpkg" "github.com/pyihe/go-pkg/sorts"
) )
type stringSlice []string type stringSlice []string
@@ -38,7 +38,7 @@ func (ss *stringSlice) Sort() {
if ss == nil { if ss == nil {
return return
} }
sortpkg.SortStrings(*ss) sorts.SortStrings(*ss)
} }
func (ss *stringSlice) PushBack(x interface{}) (bool, int) { func (ss *stringSlice) PushBack(x interface{}) (bool, int) {

View File

@@ -1,9 +1,9 @@
package slicepkg package slices
import ( import (
"fmt" "fmt"
"github.com/pyihe/go-pkg/sortpkg" "github.com/pyihe/go-pkg/sorts"
) )
type uintSlice []uint type uintSlice []uint
@@ -38,7 +38,7 @@ func (us *uintSlice) Sort() {
if us == nil { if us == nil {
return return
} }
sortpkg.SortUints(*us) sorts.SortUints(*us)
} }
func (us *uintSlice) PushBack(x interface{}) (bool, int) { func (us *uintSlice) PushBack(x interface{}) (bool, int) {

View File

@@ -1,9 +1,9 @@
package slicepkg package slices
import ( import (
"fmt" "fmt"
"github.com/pyihe/go-pkg/sortpkg" "github.com/pyihe/go-pkg/sorts"
) )
type uint16Slice []uint16 type uint16Slice []uint16
@@ -38,7 +38,7 @@ func (u16 *uint16Slice) Sort() {
if u16 == nil { if u16 == nil {
return return
} }
sortpkg.SortUint16s(*u16) sorts.SortUint16s(*u16)
} }
func (u16 *uint16Slice) PushBack(x interface{}) (bool, int) { func (u16 *uint16Slice) PushBack(x interface{}) (bool, int) {

View File

@@ -1,9 +1,9 @@
package slicepkg package slices
import ( import (
"fmt" "fmt"
"github.com/pyihe/go-pkg/sortpkg" "github.com/pyihe/go-pkg/sorts"
) )
type uint32Slice []uint32 type uint32Slice []uint32
@@ -38,7 +38,7 @@ func (i32 *uint32Slice) Sort() {
if i32 == nil { if i32 == nil {
return return
} }
sortpkg.SortUint32s(*i32) sorts.SortUint32s(*i32)
} }
func (i32 *uint32Slice) PushBack(x interface{}) (bool, int) { func (i32 *uint32Slice) PushBack(x interface{}) (bool, int) {

View File

@@ -1,9 +1,9 @@
package slicepkg package slices
import ( import (
"fmt" "fmt"
"github.com/pyihe/go-pkg/sortpkg" "github.com/pyihe/go-pkg/sorts"
) )
type uint64Slice []uint64 type uint64Slice []uint64
@@ -38,7 +38,7 @@ func (i64 *uint64Slice) Sort() {
if i64 == nil { if i64 == nil {
return return
} }
sortpkg.SortUint64s(*i64) sorts.SortUint64s(*i64)
} }
func (i64 *uint64Slice) PushBack(x interface{}) (bool, int) { func (i64 *uint64Slice) PushBack(x interface{}) (bool, int) {

View File

@@ -1,9 +1,9 @@
package slicepkg package slices
import ( import (
"fmt" "fmt"
"github.com/pyihe/go-pkg/sortpkg" "github.com/pyihe/go-pkg/sorts"
) )
type uint8Slice []uint8 type uint8Slice []uint8
@@ -38,7 +38,7 @@ func (i8 *uint8Slice) Sort() {
if i8 == nil { if i8 == nil {
return return
} }
sortpkg.SortUint8s(*i8) sorts.SortUint8s(*i8)
} }
func (i8 *uint8Slice) PushBack(x interface{}) (bool, int) { func (i8 *uint8Slice) PushBack(x interface{}) (bool, int) {

View File

@@ -1,4 +1,4 @@
package sortpkg package sorts
import "sort" import "sort"

View File

@@ -1,4 +1,4 @@
package sortpkg package sorts
import ( import (
"sort" "sort"

View File

@@ -1,4 +1,4 @@
package stringpkg package strings
import ( import (
"reflect" "reflect"

View File

@@ -1,4 +1,4 @@
package syncpkg package syncs
import ( import (
"sync/atomic" "sync/atomic"

View File

@@ -1,4 +1,4 @@
package timepkg package times
import "time" import "time"

View File

@@ -1,4 +1,4 @@
package zippkg package zips
import ( import (
"bytes" "bytes"