https://github.com/gookit/gsr
Go Standards Recommendations - common interfaces. e.g: cache, logger. Golang 一些通用的接口定义
https://github.com/gookit/gsr
go-cache go-logger golang golang-interface interface-design logger
Last synced: 6 months ago
JSON representation
Go Standards Recommendations - common interfaces. e.g: cache, logger. Golang 一些通用的接口定义
- Host: GitHub
- URL: https://github.com/gookit/gsr
- Owner: gookit
- License: mit
- Created: 2021-05-26T02:07:23.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-03-11T15:49:22.000Z (over 1 year ago)
- Last Synced: 2025-03-27T20:41:09.367Z (7 months ago)
- Topics: go-cache, go-logger, golang, golang-interface, interface-design, logger
- Language: Go
- Homepage: https://pkg.go.dev/github.com/gookit/gsr
- Size: 25.4 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GSR

[](https://pkg.go.dev/github.com/gookit/gsr)
[](https://goreportcard.com/report/github.com/gookit/gsr)
Go Standards Recommendations
## Install
```bash
go get github.com/gookit/gsr
```
## Interfaces
- [logger](logger.go)
- [cacher](cacher.go)
- [parser](parser.go)
## Usage
### Logger Interface
**Std Logger**
```go
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**
```go
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**
```go
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
```go
// DataParser interface for Marshal/Unmarshal data
type DataParser interface {
Marshal(v any) ([]byte, error)
Unmarshal(data []byte, ptr any) error
}
```
## LICENSE
[MIT](LICENSE)