rice

package module
v0.0.28 Latest Latest
Warning

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

Go to latest
Published: May 7, 2023 License: MIT Imports: 36 Imported by: 2

README

rice

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

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

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 ByteString

func ByteString(b []byte) string

ByteString []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 Compress

func Compress(b bool) lumberjackOption

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 Exists added in v0.0.28

func Exists(path string) bool

func First

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

First make return first for slice

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 InitID added in v0.0.25

func InitID(workID uint16)

func InitLogger added in v0.0.24

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

func Intersection added in v0.0.24

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

Intersection 两个 slice 的交集

func IsDir added in v0.0.28

func IsDir(path string) bool

func IsFile added in v0.0.28

func IsFile(path string) 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, error)

func LocalHostname added in v0.0.24

func LocalHostname() (string, error)

func LocalTime

func LocalTime(b bool) lumberjackOption

func LowerTitle added in v0.0.26

func LowerTitle(s string) string

func MaxAge

func MaxAge(i int) lumberjackOption

func MaxBackups

func MaxBackups(i int) lumberjackOption

func MaxNumber

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

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

func MaxSize

func MaxSize(i int) lumberjackOption

func MinNumber

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

func NewLumberjackLogger

func NewLumberjackLogger(fileName string, opts ...lumberjackOption) io.Writer

func NextID added in v0.0.25

func NextID() int64

func NextStringID added in v0.0.25

func NextStringID() string

func NotIn

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

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

func Pageination

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

Pageination 切片分页

func RandNumber added in v0.0.25

func RandNumber(max int64) int64

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

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 Reverse added in v0.0.24

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

Reverse 反转 slice

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 TimerRun

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

func TodayZeroTime

func TodayZeroTime() time.Time

func TodayZeroTimestamp

func TodayZeroTimestamp() int64

func VersionInfo added in v0.0.27

func VersionInfo() (string, string)

func ZeroTime

func ZeroTime(tm time.Time) time.Time

func ZeroTimestamp

func ZeroTimestamp(ts int64) int64

Types

type AESCrypter

type AESCrypter interface {
	Encrypt(keyString, plainString string) (string, error)
	Decrypt(keyString, cipherString string) (string, error)
}

func NewCTRCrypt

func NewCTRCrypt() AESCrypter

type CTRCrypt

type CTRCrypt struct{}

func (*CTRCrypt) Decrypt

func (*CTRCrypt) Decrypt(keyString, cipherString string) (string, error)

func (*CTRCrypt) Encrypt

func (*CTRCrypt) Encrypt(keyString, plainString string) (string, error)

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 JsonUnmarshal

type JsonUnmarshal struct{}

func (*JsonUnmarshal) ReadConfig

func (j *JsonUnmarshal) ReadConfig(p []byte, v any) error

func (*JsonUnmarshal) ReadConfigFromFile

func (j *JsonUnmarshal) ReadConfigFromFile(path string, v any) 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 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 TomlUnmarshal

type TomlUnmarshal struct{}

func (*TomlUnmarshal) ReadConfig

func (t *TomlUnmarshal) ReadConfig(p []byte, v any) error

func (*TomlUnmarshal) ReadConfigFromFile

func (t *TomlUnmarshal) ReadConfigFromFile(path string, v any) error

type UnmarshalConfiger

type UnmarshalConfiger interface {
	ReadConfig(p []byte, v any) error
	ReadConfigFromFile(path string, v any) error
}

func NewJsonUnmarshal

func NewJsonUnmarshal() UnmarshalConfiger

func NewTomlUnmarshal

func NewTomlUnmarshal() UnmarshalConfiger

func NewYamlUnmarshal

func NewYamlUnmarshal() UnmarshalConfiger

type YamlUnmarshal

type YamlUnmarshal struct{}

func (*YamlUnmarshal) ReadConfig

func (y *YamlUnmarshal) ReadConfig(p []byte, v any) error

func (*YamlUnmarshal) ReadConfigFromFile

func (y *YamlUnmarshal) ReadConfigFromFile(path string, v any) error

Jump to

Keyboard shortcuts

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