rice

package module
v0.0.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2022 License: MIT Imports: 22 Imported by: 0

README

rice

封装了一些常用但又记不住名字的方法。

import "github.com/woxingliu/rice"
go mod tidy

Usage

Database

postgresql

pg, err := rice.NewPostgresDB("postgres://postgres:123456@localhost:5432/user?sslmode=disable")
if err != nil {
	return err
}
defer pg.Close()

mariadb

mariaDB := rice.NewMariaDB("root:root@tcp(localhost:3306)/user?parseTime=True&loc=Local&charset=utf8mb4")
defer mariaDB.Close()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AESDecrypt added in v0.0.9

func AESDecrypt(key []byte, s string) (string, error)

func AESEncrypt added in v0.0.9

func AESEncrypt(key []byte, s string) (string, error)

func AESNewCBCDecrypter added in v0.0.9

func AESNewCBCDecrypter(keyString, cipherString string) (string, error)

func AESNewCBCEncrypter added in v0.0.9

func AESNewCBCEncrypter(keyString, plainString string) (string, error)

func AESNewCFBDecrypter added in v0.0.9

func AESNewCFBDecrypter()

func AESNewCFBEncrypter added in v0.0.9

func AESNewCFBEncrypter()

func AESNewGCMDecrypt added in v0.0.9

func AESNewGCMDecrypt(keyString, nonceString, ciphertext string) (string, error)

func AESNewGCMEncrypt added in v0.0.9

func AESNewGCMEncrypt(keyString, plaintext string) (string, error)

func BCryptCompareHashAndPassword added in v0.0.9

func BCryptCompareHashAndPassword(pwd, hash string) bool

BCryptCompareHashAndPassword true or false

func BCryptGenerateFromPassword added in v0.0.9

func BCryptGenerateFromPassword(pwd string) (string, error)

BCryptGenerateFromPassword generate hash from password

func ByteString

func ByteString(b []byte) string

ByteString []byte to string

func BytesNewBufferString added in v0.0.9

func BytesNewBufferString(b []byte) string

BytesNewBufferString []byte to string

func CloseRedisClient added in v0.0.10

func CloseRedisClient() error

func FmtSprintfByte added in v0.0.9

func FmtSprintfByte(b []byte) string

FmtSprintfByte []byte to string

func GetRedisClient added in v0.0.10

func GetRedisClient() *redis.Client

func NewRedisClient added in v0.0.8

func NewRedisClient(addr string, opts ...RedisOption) *redis.Client

func SliceRemoveIndex added in v0.0.10

func SliceRemoveIndex(slice []int, s int) []int

SliceRemoveIndex 移除 slice 中的一个元素

func SliceRemoveIndexUnOrder added in v0.0.10

func SliceRemoveIndexUnOrder(s []int, i int) []int

SliceRemoveIndexUnOrder 移除 slice 中的一个元素(无序,但效率高)

func StrconvFormatInt

func StrconvFormatInt(i int64) string

StrconvFormatInt 1645270804 to "1645270804"

func StrconvParseFloat added in v0.0.8

func StrconvParseFloat(i int) (float64, error)

StrconvParseFloat int/100 to float64 保留 2 位小数点 example: 2333 -> 23.33

func StrconvParseInt

func StrconvParseInt(s string) (int64, error)

StrconvParseInt "1645270804" to 1645270804

func StringByte

func StringByte(s string) []byte

StringByte string to []byte

func TimeFormat

func TimeFormat(tm time.Time) string

TimeFormat time.Time to "2006-01-02 15:04:05"

func TimeNowFormat

func TimeNowFormat() string

TimeNowFormat time.Time to "2006-01-02 15:04:05"

func TimeParse

func TimeParse(s string) (time.Time, error)

TimeParse "2006-01-02 15:04:05" to time.Time

func TimeUnix

func TimeUnix(sec int64) time.Time

TimeUnix 1645270804 to time.Time

func UUIDNewString added in v0.0.10

func UUIDNewString() string

UUIDNewString creates a new random UUID

Types

type MariaDB added in v0.0.8

type MariaDB struct {
	*sql.DB
	// contains filtered or unexported fields
}

func GetMariaDB added in v0.0.8

func GetMariaDB() *MariaDB

func NewMariaDB added in v0.0.8

func NewMariaDB(url string, opts ...MariaDBOption) *MariaDB

func (*MariaDB) Close added in v0.0.8

func (db *MariaDB) Close()

type MariaDBOption added in v0.0.8

type MariaDBOption func(*MariaDB)

func ConnAttempts_MYSQL added in v0.0.8

func ConnAttempts_MYSQL(attempts int) MariaDBOption

ConnAttempts_MYSQL 尝试连接数据库次数

func ConnMaxIdleTime_MYSQL added in v0.0.8

func ConnMaxIdleTime_MYSQL(d time.Duration) MariaDBOption

ConnMaxIdleTime_MYSQL 一个连接空闲的最大时长

func ConnMaxLifetime_MYSQL added in v0.0.8

func ConnMaxLifetime_MYSQL(d time.Duration) MariaDBOption

ConnMaxLifetime_MYSQL 一个连接使用的最大时长

func ConnTimeout_MYSQL added in v0.0.8

func ConnTimeout_MYSQL(timeout time.Duration) MariaDBOption

ConnTimeout_MYSQL 连接数据库超时时间

func MaxIdleConns_MYSQL added in v0.0.8

func MaxIdleConns_MYSQL(size int) MariaDBOption

MaxIdleConns_MYSQL 最大闲置的连接数

func MaxOpenConns_MYSQL added in v0.0.8

func MaxOpenConns_MYSQL(size int) MariaDBOption

MaxOpenConns_MYSQL 最大打开的连接数

type Postgres added in v0.0.8

type Postgres struct {
	Builder squirrel.StatementBuilderType
	Pool    *pgxpool.Pool
	// contains filtered or unexported fields
}

Postgres -.

func GetPostgresDB added in v0.0.8

func GetPostgresDB() *Postgres

func NewPostgresDB added in v0.0.8

func NewPostgresDB(url string, opts ...PostgresOption) (*Postgres, error)

NewPostgresDB -.

func (*Postgres) Close added in v0.0.8

func (p *Postgres) Close()

Close -.

type PostgresOption added in v0.0.8

type PostgresOption func(*Postgres)

Option -.

func ConnAttempts added in v0.0.10

func ConnAttempts(attempts int) PostgresOption

ConnAttempts -.

func ConnTimeout added in v0.0.10

func ConnTimeout(timeout time.Duration) PostgresOption

ConnTimeout -.

func MaxPoolSize added in v0.0.10

func MaxPoolSize(size int) PostgresOption

MaxPoolSize -.

type RedisOption added in v0.0.10

type RedisOption func(*redis.Options)

func RedisDB added in v0.0.10

func RedisDB(db int) RedisOption

func RedisPassword added in v0.0.10

func RedisPassword(pwd string) RedisOption

func RedisPoolSize added in v0.0.10

func RedisPoolSize(poolSize int) RedisOption

Directories

Path Synopsis
database
Package httpserver implements HTTP server.
Package httpserver implements HTTP server.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL