gsr

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2023 License: MIT Imports: 3 Imported by: 6

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
}
DataParser interface
// DataParser interface for Marshal/Unmarshal data
type DataParser interface {
	Marshal(v any) ([]byte, error)
	Unmarshal(data []byte, ptr any) 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 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 interface {
	Marshaler
	Unmarshaler
}

DataParser interface for Marshal/Unmarshal data

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 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 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