utils

package
v0.5.8 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2023 License: MIT Imports: 5 Imported by: 2

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func PanicFn added in v0.2.2

func PanicFn(fn func() error)

PanicFn panic if err is not nil

func RedisMarshal added in v0.4.26

func RedisMarshal(b any) ([]byte, error)

RedisMarshal use gob encode

Example
package main

import (
	"fmt"

	"github.com/datewu/gtea/utils"
)

type anCache []string

// MarshalBinary implements the encoding.BinaryMarshaler interface.
func (l anCache) MarshalBinary() ([]byte, error) {
	type a anCache
	a1 := a(l)
	return utils.RedisMarshal(a1)
}

// UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
func (l *anCache) UnmarshalBinary(data []byte) error {
	type a anCache
	a1 := (*a)(l)
	return utils.RedisUnMarshal(data, a1)
}

func main() {
	data := anCache{"hello", "world"}
	bs, err := data.MarshalBinary()
	// before go1.21.0
	// [15 255 129 2 1 1 1 97 1 255 130 0 1 12 0 0 16 255 130 0 2 5 104 101 108 108 111 5 119 111 114 108 100]
	if err != nil {
		panic(err)
	}
	fmt.Println(bs)

}
Output:

[14 127 2 1 1 1 97 1 255 128 0 1 12 0 0 16 255 128 0 2 5 104 101 108 108 111 5 119 111 114 108 100]

func RedisUnMarshal added in v0.4.26

func RedisUnMarshal(data []byte, b any) error

RedisUnMarshal use gob decode

Types

type Pagination added in v0.2.2

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

Pagination represents a pagination object.

func NewPagination added in v0.2.2

func NewPagination(page, perPage int) *Pagination

NewPagination returns a new Pagination object.

func ParsePagination added in v0.5.3

func ParsePagination(r *http.Request) *Pagination

ParsePagination parse page & per_page query returns a new Pagination object.

func (*Pagination) Limit added in v0.2.2

func (p *Pagination) Limit() int

func (*Pagination) Offset added in v0.2.2

func (p *Pagination) Offset() int

func (*Pagination) SetPage added in v0.2.2

func (p *Pagination) SetPage(page int)

Jump to

Keyboard shortcuts

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