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 (
"unsafe"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,10 +1,10 @@
package listpkg
package lists
import (
"container/list"
"sync"
"github.com/pyihe/go-pkg/mathpkg"
"github.com/pyihe/go-pkg/maths"
)
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) {
start = mathpkg.MaxInt(mathpkg.MinInt(start, length), 0)
end = mathpkg.MaxInt(mathpkg.MinInt(end, length), 0)
start = maths.MaxInt(maths.MinInt(start, length), 0)
end = maths.MaxInt(maths.MinInt(end, length), 0)
return start, end
}

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,4 +1,4 @@
package logpkg
package logs
import (
"io"
@@ -6,7 +6,7 @@ import (
"strings"
"time"
"github.com/pyihe/go-pkg/netpkg"
"github.com/pyihe/go-pkg/nets"
rotatelogs "github.com/lestrrat-go/file-rotatelogs"
"go.uber.org/zap"
@@ -57,7 +57,7 @@ func newZapLogger(opts ...LogOption) (Logger, error) {
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)
allLevel := zap.LevelEnablerFunc(func(lv zapcore.Level) bool {

View File

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

View File

@@ -1,10 +1,10 @@
package mappkg
package maps
import (
"reflect"
"strconv"
"github.com/pyihe/go-pkg/errpkg"
"github.com/pyihe/go-pkg/errors"
)
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) {
value, ok := p.Get(key)
if !ok {
return "", errpkg.New("not exist key: " + key)
return "", errors.New("not exist key: " + key)
}
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) {
value, ok := p.Get(key)
if !ok {
return 0, errpkg.New("not exist key: " + key)
return 0, errors.New("not exist key: " + key)
}
t := reflect.TypeOf(value)
v := reflect.ValueOf(value)
@@ -65,7 +65,7 @@ func (p Param) GetInt64(key string) (n int64, err error) {
case reflect.Float32, reflect.Float64:
n = int64(v.Float())
default:
err = errpkg.New("unknown type: " + t.String())
err = errors.New("unknown type: " + t.String())
}
return
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,4 +1,4 @@
package redispkg
package rediss
func (conn *myRedisConn) HGet(key string, field string) ([]byte, error) {
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 {
err := conn.rpush(key, values...)

View File

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

View File

@@ -1,4 +1,4 @@
package redispkg
package rediss
func (conn *myRedisConn) SADD(key string, members ...interface{}) error {
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) {
keys, err = conn.getKeys(pattern)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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