rice

package module
v0.0.46 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2024 License: MIT Imports: 51 Imported by: 2

README

rice

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

Documentation

Index

Constants

View Source
const ISSUER = "rice"

Variables

View Source
var (
	// Cert is a self signed certificate
	Cert tls.Certificate
	// CertPool contains the self signed certificate
	CertPool *x509.CertPool
)

Functions

func AESGCMDecryptFile added in v0.0.45

func AESGCMDecryptFile(key, inputFile, outputFile string) error

func AESGCMDecryptText added in v0.0.45

func AESGCMDecryptText(key string, ciphertextHex string) (string, error)

func AESGCMEncryptFile added in v0.0.45

func AESGCMEncryptFile(key, inputFile, outputFile string) error

func AESGCMEncryptText added in v0.0.45

func AESGCMEncryptText(key, plaintext string) (string, error)

func AppendFileIfExists added in v0.0.40

func AppendFileIfExists(name string, data []byte) error

func BCryptCompareHashAndPassword

func BCryptCompareHashAndPassword(pwd, hash string) bool

BCryptCompareHashAndPassword true or false

func BCryptGenerateFromPassword

func BCryptGenerateFromPassword(pwd string) (string, error)

BCryptGenerateFromPassword generate hash from password

func ByteStringUnsafe added in v0.0.41

func ByteStringUnsafe(b []byte) string

ByteStringUnsafe []byte to string

func BytesBufferString added in v0.0.24

func BytesBufferString(b []byte) string

BytesBufferString []byte to string

func Collect added in v0.0.24

func Collect[T any](iter Iterator[T]) []T

func CountWeek added in v0.0.35

func CountWeek(TimeFormat string) int

CountWeek 获取当前日期为当月第几周

func CronRun

func CronRun(ctx context.Context, corn string, task ...func()) error

func CronRunM

func CronRunM(ctx context.Context, corn string, task ...func()) error

func DeDuplicate added in v0.0.24

func DeDuplicate[T comparable](items []T) []T

DeDuplicate slice 去重

func DeDuplicateInPlace added in v0.0.24

func DeDuplicateInPlace[T Numbers](items []T) []T

DeDuplicateInPlace slice 就地去重

func Difference added in v0.0.24

func Difference[T comparable](items1, items2 []T) []T

Difference 取 items1 中有,而 items2 中没有的

func DifferenceBoth added in v0.0.24

func DifferenceBoth[T comparable](items1, items2 []T) []T

DifferenceBoth 取 slice1, slice2 的差集

func FileExists added in v0.0.40

func FileExists(filename string) bool

FileExists 文件是否存在

func First

func First[T any](objs []T) (T, bool)

First make return first for slice

func GenerateOTP added in v0.0.37

func GenerateOTP(account string) (string, string, error)

func GenerateRSA added in v0.0.45

func GenerateRSA() ([]byte, []byte, error)

func Get added in v0.0.45

func Get[R any](url string) (R, error)

func Hash added in v0.0.39

func Hash(s string) string

func IP added in v0.0.45

func IP() string

func In

func In[T comparable](e T, items []T) bool

In e 在 items 中吗? true 在,false 不在

func InitCert added in v0.0.24

func InitCert(certPEM, keyPEM []byte) error

func InitLogger added in v0.0.24

func InitLogger(w ...io.Writer)

func InitYitterID added in v0.0.45

func InitYitterID(workID uint16)

func InitZerolog added in v0.0.38

func InitZerolog(level string, w ...io.Writer)

func Intersection added in v0.0.24

func Intersection[T comparable](s1, s2 []T) (inter []T)

Intersection 两个 slice 的交集

func IsASCII added in v0.0.45

func IsASCII(s string) bool

func IsNil added in v0.0.40

func IsNil(x any) bool

func IsTimeExistIntersection added in v0.0.24

func IsTimeExistIntersection(startTime, endTime time.Time, anotherStartTime, anotherEndTime time.Time) bool

IsTimeExistIntersection 两个时间段是否有交集 false 没有交集,true 有交集

func IsTimestampExistIntersection added in v0.0.24

func IsTimestampExistIntersection(startTime, endTime int64, anotherStartTime, anotherEndTime int64) bool

IsTimestampExistIntersection 两个时间段是否有交集 false 没有交集,true 有交集

func JsonEncode added in v0.0.27

func JsonEncode(t any) ([]byte, error)

func JsonEncodeIndent added in v0.0.27

func JsonEncodeIndent(t any, prefix, indent string) ([]byte, error)

func LocalAddr added in v0.0.24

func LocalAddr() string

func LowerTitle added in v0.0.26

func LowerTitle(s string) string

LowerTitle 首字母小写

func MaxNumber

func MaxNumber[T Numbers](e ...T) T

MaxNumber booleans, numbers, strings, pointers, channels, arrays

func MinNumber

func MinNumber[T Numbers](e ...T) T

func NewConsoleWriter added in v0.0.37

func NewConsoleWriter() zerolog.ConsoleWriter

func NewEtcdClient added in v0.0.45

func NewEtcdClient(endpoints []string) (*clientv3.Client, error)

func NewFileWriter added in v0.0.42

func NewFileWriter(fileName string, opts ...LumberjackOption) *lumberjack.Logger

func NewRedisClient added in v0.0.42

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

func NewResolver added in v0.0.45

func NewResolver(address string) *net.Resolver

func NewTelegramBot added in v0.0.40

func NewTelegramBot(token, proxy string) (*tgbotapi.BotAPI, error)

func NewTelegramBotNotifier added in v0.0.30

func NewTelegramBotNotifier(token, proxy string, chatID ...int64) (*notify.Notify, error)

func NewTelegramNotifier added in v0.0.40

func NewTelegramNotifier(token, proxy string) (*telegram.Telegram, error)

func NextUUID added in v0.0.35

func NextUUID() string

func NextXID added in v0.0.40

func NextXID() string

func NextYitterID added in v0.0.45

func NextYitterID() int64

func NextYitterStringID added in v0.0.45

func NextYitterStringID() string

func NotIn

func NotIn[T comparable](e T, items []T) bool

NotIn e 不在 s 中吗? true 不在, false 在

func Now added in v0.0.45

func Now() string

func Pageination

func Pageination[T any](page, pageSize int, s []T) []T

Pageination 切片分页

func PathExists added in v0.0.40

func PathExists(path string) bool

PathExists 路径是否存在

func PathIsDir added in v0.0.40

func PathIsDir(path string) bool

PathIsDir 路径是否是文件夹

func PathIsFile added in v0.0.40

func PathIsFile(path string) bool

PathIsFile 路径是否是文件

func Pinyin added in v0.0.36

func Pinyin(s string) string

func PostForm added in v0.0.45

func PostForm[R any](url string, data url.Values) (R, error)

PostForm application/x-www-form-urlencoded

func PostJson added in v0.0.45

func PostJson[T, R any](url string, data T) (R, error)

PostJson application/json

func PostMultipartForm added in v0.0.45

func PostMultipartForm[R any](url string, data url.Values, wFunc WriteMutipartFunc) (R, error)

PostMultipartForm multipart/form-data

func PunycodeEncode added in v0.0.45

func PunycodeEncode(s string) (string, error)

func RandNumber added in v0.0.25

func RandNumber(max int64) int64

RandNumber generate a number range [0, max)

func RandomBytes added in v0.0.45

func RandomBytes(length int) ([]byte, error)

func RandomHexString added in v0.0.45

func RandomHexString(length int) (string, error)

func Reduce added in v0.0.24

func Reduce[T, V any](iter Iterator[V], f Reducer[T, V]) T

Reduce values iterated over to a single value

func RemoveInvisibleChars added in v0.0.26

func RemoveInvisibleChars(s string) string

RemoveInvisibleChars 移除字符串中的不可见字符

func RemoveItem added in v0.0.24

func RemoveItem[T any](items []T, index int) []T

RemoveItem 移除 slice 中的一个元素

func RemoveItemNoOrder added in v0.0.24

func RemoveItemNoOrder[T any](items []T, index int) []T

RemoveItemNoOrder 移除 slice 中的一个元素,无序

func Request added in v0.0.45

func Request[R any](request *http.Request) (R, error)

func Reverse added in v0.0.24

func Reverse[T any](items []T)

Reverse 反转 slice

func SHA256 added in v0.0.45

func SHA256(text string) string

func SetJsonSlog added in v0.0.45

func SetJsonSlog()

func SetTextSlog added in v0.0.45

func SetTextSlog()

func SplitNString added in v0.0.39

func SplitNString(s string, index int) string

func StringByte

func StringByte(s string) []byte

StringByte string to []byte

func StringByteUnsafe

func StringByteUnsafe(s string) []byte

StringByteUnsafe string to []byte

func TickerRun

func TickerRun(ctx context.Context, d time.Duration, task ...Task) error

func TickerRunContext

func TickerRunContext(ctx context.Context, d time.Duration, task ...TaskContext) error

TickerRunContext 立即开始以 ticker 的方式执行 task

func TickerRunWithStartTimeContext

func TickerRunWithStartTimeContext(ctx context.Context, wg *sync.WaitGroup, tm time.Time, d time.Duration, task ...TaskContext) error

TickerRunWithStartTimeContext 到达 tm 时间之后,开始以 tikcer 的方式执行 task

func TimeString added in v0.0.45

func TimeString(tm time.Time) string

func TimerRun

func TimerRun(ctx context.Context, tm time.Time, task ...Task) error

func TodayZeroTime

func TodayZeroTime() time.Time

func TodayZeroTimestamp

func TodayZeroTimestamp() int64

func TrackTime added in v0.0.40

func TrackTime(pre time.Time) time.Duration

func VersionInfo added in v0.0.27

func VersionInfo() (string, string)

VersionInfo 返回 git revision 和 go version

func WriteFileIfNotExists added in v0.0.40

func WriteFileIfNotExists(name string, data []byte) error

func WriteFileWhatever added in v0.0.40

func WriteFileWhatever(name string, data []byte) error

func ZeroTime

func ZeroTime(tm time.Time) time.Time

func ZeroTimestamp

func ZeroTimestamp(ts int64) int64

Types

type Iterator added in v0.0.24

type Iterator[T any] interface {
	Next() bool
	Value() T
}

func Filter

func Filter[T any](iter Iterator[T], pred func(T) bool) Iterator[T]

func Map

func Map[T any](iter Iterator[T], f func(T) T) Iterator[T]

func NewSliceIterator added in v0.0.24

func NewSliceIterator[T any](xs []T) Iterator[T]

NewSliceIterator Create an iterator over the slice xs

type LumberjackOption

type LumberjackOption func(*lumberjack.Logger)

func Compress

func Compress(b bool) LumberjackOption

func LocalTime

func LocalTime(b bool) LumberjackOption

func MaxAge

func MaxAge(i int) LumberjackOption

func MaxBackups

func MaxBackups(i int) LumberjackOption

func MaxSize

func MaxSize(i int) LumberjackOption

type NotifyHook added in v0.0.32

type NotifyHook struct {
	Notifier *notify.Notify
}

func NewNotifyHook added in v0.0.32

func NewNotifyHook() *NotifyHook

func (*NotifyHook) AddTelegramNotifierHook added in v0.0.42

func (t *NotifyHook) AddTelegramNotifierHook(token, proxy string, chatID ...int64) *NotifyHook

func (*NotifyHook) Run added in v0.0.32

func (t *NotifyHook) Run(e *zerolog.Event, level zerolog.Level, message string)

func (*NotifyHook) Write added in v0.0.33

func (t *NotifyHook) Write(p []byte) (n int, err error)

type Numbers

type Numbers interface {
	uint8 | uint16 | uint32 | uint64 | int8 | int16 | int32 | int64 | float32 | float64 | int | uint
}

type RSASign

type RSASign struct {
	PrivateKey *rsa.PrivateKey
	PublicKey  *rsa.PublicKey
}

func (*RSASign) Sign

func (r *RSASign) Sign(data []byte) ([]byte, error)

func (*RSASign) Verify

func (r *RSASign) Verify(data []byte, signature []byte) error

type RedisOption

type RedisOption func(*redis.Options)

type Reducer added in v0.0.24

type Reducer[T, V any] func(accum T, value V) T

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server -.

func NewHttpServer

func NewHttpServer(handler http.Handler, opts ...ServerOption) *Server

NewHttpServer -.

func (*Server) Notify

func (s *Server) Notify() <-chan error

Notify -.

func (*Server) Shutdown

func (s *Server) Shutdown() error

Shutdown -.

type ServerOption

type ServerOption func(*Server)

ServerOption -.

func Port

func Port(port string) ServerOption

Port -.

func ReadTimeout

func ReadTimeout(timeout time.Duration) ServerOption

ReadTimeout -.

func ShutdownTimeout

func ShutdownTimeout(timeout time.Duration) ServerOption

ShutdownTimeout -.

func WriteTimeout

func WriteTimeout(timeout time.Duration) ServerOption

WriteTimeout -.

type Signer

type Signer interface {
	Sign(data []byte) ([]byte, error)
	Verify(data []byte, signature []byte) error
}

func NewRSASignFromBytes

func NewRSASignFromBytes(privateKeyData, publicKeyData []byte) (Signer, error)

func NewRSASignFromFile

func NewRSASignFromFile(privateKeyFile, publicKeyFile string) (Signer, error)

type SliceIterator added in v0.0.24

type SliceIterator[T any] struct {
	Elements []T
	// contains filtered or unexported fields
}

func (*SliceIterator[T]) Next added in v0.0.24

func (iter *SliceIterator[T]) Next() bool

Next Move to next value in collection

func (*SliceIterator[T]) Value added in v0.0.24

func (iter *SliceIterator[T]) Value() T

Value Get current element

type Task

type Task func() error

type TaskContext

type TaskContext func(ctx context.Context) error

type WriteMutipartFunc added in v0.0.45

type WriteMutipartFunc func(w *multipart.Writer) error

Jump to

Keyboard shortcuts

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