rice

package module
v0.0.49 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2024 License: MIT Imports: 48 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
)
View Source
var YitterBaseTime = time.Date(2022, time.January, 1, 0, 0, 0, 0, time.Local)

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 AppendFile added in v0.0.47

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

AppendFile 往文件末尾追加内容

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 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 DeleteForm added in v0.0.49

func DeleteForm[R any](hc *HttpClient, url string, data url.Values) (R, error)

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 Do added in v0.0.48

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

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](hc *HttpClient, url string, params url.Values) (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 JsonIndentEncode added in v0.0.47

func JsonIndentEncode(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 NewFileWriter added in v0.0.42

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

func NewResolver added in v0.0.45

func NewResolver(address string) *net.Resolver

func NextNanoID added in v0.0.47

func NextNanoID() string

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 NowTimeString added in v0.0.49

func NowTimeString() string

func NullTimeString added in v0.0.47

func NullTimeString(tm sql.NullTime) string

func Pagination added in v0.0.47

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

Pagination 切片分页

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, sep string) string

func PostForm added in v0.0.45

func PostForm[R any](hc *HttpClient, 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](hc *HttpClient, url string, data T) (R, error)

PostJson application/json

func PostMultipartForm added in v0.0.45

func PostMultipartForm[R any](hc *HttpClient, url string, fieldValues url.Values, files []FormFile) (R, error)

PostMultipartForm multipart/form-data

func PrintAllElements added in v0.0.47

func PrintAllElements[E comparable](s *Set[E])

func PrintAllElementsPull added in v0.0.47

func PrintAllElementsPull[E comparable](s *Set[E])

func PrintAllElementsPush added in v0.0.47

func PrintAllElementsPush[E comparable](s *Set[E])

func PunycodeEncode added in v0.0.45

func PunycodeEncode(s string) (string, error)

func PutForm added in v0.0.49

func PutForm[R any](hc *HttpClient, url string, data url.Values) (R, error)

PutForm application/x-www-form-urlencoded

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 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 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 WriteFile added in v0.0.47

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

WriteFile 写入文件

func WriteFileSafe added in v0.0.47

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

WriteFileSafe 安全的写入文件,如果文件已经存在则跳过写入

func ZeroTime

func ZeroTime(tm time.Time) time.Time

func ZeroTimestamp

func ZeroTimestamp(ts int64) int64

Types

type DefaultResponse added in v0.0.48

type DefaultResponse map[string]any

type FormFile added in v0.0.48

type FormFile struct {
	Fieldname string
	Filename  string
	Data      io.Reader
}

type HttpClient added in v0.0.48

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

func DefaultHttpClient added in v0.0.48

func DefaultHttpClient() *HttpClient

func NewHttpClient added in v0.0.48

func NewHttpClient(client *http.Client, logger *slog.Logger) *HttpClient

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

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

type Set added in v0.0.47

type Set[E comparable] struct {
	// contains filtered or unexported fields
}

Set holds a set of elements.

func New added in v0.0.47

func New[E comparable]() *Set[E]

New returns a new Set.

func Union added in v0.0.47

func Union[E comparable](s1, s2 *Set[E]) *Set[E]

Union returns the union of two sets.

func (*Set[E]) Add added in v0.0.47

func (s *Set[E]) Add(v E)

Add adds an element to a set.

func (*Set[E]) All added in v0.0.47

func (s *Set[E]) All() iter.Seq[E]

All is an iterator over the elements of s.

func (*Set[E]) Contains added in v0.0.47

func (s *Set[E]) Contains(v E) bool

Contains reports whether an element is in a set.

func (*Set[E]) Pull added in v0.0.47

func (s *Set[E]) Pull() (func() (E, bool), func())

Pull returns a next function that returns each element of s with a bool for whether the value is valid. The stop function should be called when finished calling the next function.

func (*Set[E]) Push added in v0.0.47

func (s *Set[E]) Push(f func(E) bool)

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

Jump to

Keyboard shortcuts

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