Skip to content
/ gsr Public

Go Standards Recommendations - common interfaces. e.g: cache, logger. Golang 一些通用的接口定义

License

Notifications You must be signed in to change notification settings

gookit/gsr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Go Standards Recommendations - common interfaces. e.g: cache, logger. Golang 一些通用的接口定义

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages