gsr

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2025 License: MIT Imports: 3 Imported by: 6 modules, 6 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

GSR

GitHub go.mod Go version GoDoc Go Report Card

Go Standards Recommendations

Install

go get github.com/gookit/gsr

Interfaces

Usage

Logger Interface

Std Logger

package main
import (
	"github.com/gookit/gsr"
)

type MyApp struct {
	logger gsr.StdLogger // std logger
}

func (ma *MyApp) SetLogger(logger gsr.StdLogger)  {
	ma.logger = logger
}

Full Logger

package main
import (
	"github.com/gookit/gsr"
)

type MyApp struct {
	logger gsr.Logger // full logger
}

func (ma *MyApp) SetLogger(logger gsr.Logger)  {
	ma.logger = logger
}
Cache Interface

Simple Cache

package main
import (
	"github.com/gookit/gsr"
)

type MyApp struct {
	cacher gsr.SimpleCacher
}

func (ma *MyApp) SetCacher(cacher gsr.SimpleCacher)  {
	ma.cacher = cacher
}
Serialize interface
// Serializer interface definition
type Serializer interface {
	Serialize(v any) ([]byte, error)
	Deserialize(data []byte, v any) error
}

// GoSerializer interface definition
type GoSerializer interface {
	Marshal(v any) ([]byte, error)
	Unmarshal(v []byte, ptr any) error
}

// Codec interface definition
type Codec interface {
	Decode(blob []byte, v any) (err error)
	Encode(v any) (out []byte, err error)
}

LICENSE

MIT

Documentation

Overview

Package gsr is the Go standards recommendations interface definitions.

Source code and other details for the project are available at GitHub:

https://github.com/gookit/gsr

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Codec added in v0.1.1

type Codec interface {
	Decode(blob []byte, v any) (err error)
	Encode(v any) (out []byte, err error)
}

Codec interface definition

type CodedCacher added in v0.0.4

type CodedCacher interface {
	SimpleCacher

	// GetAs get and decode cache value to object ptr
	GetAs(key string, ptr any) error
}

CodedCacher interface.

type ContextCacher added in v0.0.5

type ContextCacher interface {
	SimpleCacher
	// WithContext and clone new cacher
	WithContext(ctx context.Context) ContextCacher
}

ContextCacher interface.

type ContextOpCacher added in v0.0.7

type ContextOpCacher interface {
	SimpleCacher

	// HasWithCtx basic operation
	HasWithCtx(ctx context.Context, key string) bool
	DelWithCtx(ctx context.Context, key string) error
	GetWithCtx(ctx context.Context, key string) any
	SetWithCtx(ctx context.Context, key string, val any, ttl time.Duration) error

	// MGetWithCtx multi keys operation
	MGetWithCtx(ctx context.Context, keys []string) map[string]any
	MSetWithCtx(ctx context.Context, values map[string]any, ttl time.Duration) error
	MDelWithCtx(ctx context.Context, keys []string) error
}

ContextOpCacher interface.

type DataParser added in v0.0.8

type DataParser = GoSerializer

DataParser interface Deperacted

type DecodeFunc added in v0.1.1

type DecodeFunc func(blob []byte, v any) (err error)

DecodeFunc definition

type EncodeFunc added in v0.1.1

type EncodeFunc func(v any) (out []byte, err error)

EncodeFunc definition

type GenLogger added in v0.0.5

type GenLogger interface {
	Debug(v ...any)
	Debugf(format string, v ...any)
	Info(v ...any)
	Infof(format string, v ...any)
	Warn(v ...any)
	Warnf(format string, v ...any)
	Error(v ...any)
	Errorf(format string, v ...any)
}

GenLogger generic logger interface definition

type GoSerializer added in v0.1.1

type GoSerializer interface {
	Marshal(v any) ([]byte, error)
	Unmarshal(v []byte, ptr any) error
}

GoSerializer interface definition

type Logger

type Logger interface {
	StdLogger
	GenLogger
}

Logger interface definition

type MarshalFunc added in v0.0.6

type MarshalFunc func(v any) ([]byte, error)

MarshalFunc define

func (MarshalFunc) Marshal added in v0.0.6

func (m MarshalFunc) Marshal(v any) ([]byte, error)

Marshal implements the Marshaler

type Marshaler added in v0.0.3

type Marshaler interface {
	Marshal(v any) ([]byte, error)
}

Marshaler interface

type Printer

type Printer interface {
	Print(v ...any)
	Printf(format string, v ...any)
	Println(v ...any)
}

Printer interface definition

type Serializer added in v0.1.1

type Serializer interface {
	Serialize(v any) ([]byte, error)
	Deserialize(data []byte, v any) error
}

Serializer interface definition

type SimpleCacher added in v0.0.2

type SimpleCacher interface {
	// Closer close cache handle
	io.Closer
	// Clear all cache data
	Clear() error

	// Has basic operation
	Has(key string) bool
	Del(key string) error
	Get(key string) any
	Set(key string, val any, ttl time.Duration) error

	// GetMulti multi operation
	GetMulti(keys []string) map[string]any
	SetMulti(values map[string]any, ttl time.Duration) error
	DelMulti(keys []string) error
}

SimpleCacher interface definition

type StdLogger

type StdLogger interface {
	Printer
	Fatal(v ...any)
	Fatalf(format string, v ...any)
	Fatalln(v ...any)
	Panic(v ...any)
	Panicf(format string, v ...any)
	Panicln(v ...any)
}

StdLogger interface definition. refer the go "log" package.

type UnmarshalFunc added in v0.0.6

type UnmarshalFunc func(v []byte, ptr any) error

UnmarshalFunc define

func (UnmarshalFunc) Unmarshal added in v0.0.6

func (u UnmarshalFunc) Unmarshal(v []byte, ptr any) error

Unmarshal implements the Unmarshaler

type Unmarshaler added in v0.0.6

type Unmarshaler interface {
	Unmarshal(v []byte, ptr any) error
}

Unmarshaler interface

Jump to

Keyboard shortcuts

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