model: split options, add logger

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2020-08-29 17:40:25 +03:00
parent 0005f23585
commit eb1b14da8a
2 changed files with 39 additions and 27 deletions

View File

@ -1,12 +1,6 @@
// Package model is an interface for data modelling // Package model is an interface for data modelling
package model package model
import (
"github.com/unistack-org/micro/v3/codec"
"github.com/unistack-org/micro/v3/store"
"github.com/unistack-org/micro/v3/sync"
)
// Model provides an interface for data modelling // Model provides an interface for data modelling
type Model interface { type Model interface {
// Initialise options // Initialise options
@ -37,24 +31,3 @@ type Entity interface {
// Read a value as a concrete type // Read a value as a concrete type
Read(v interface{}) error Read(v interface{}) error
} }
type Options struct {
// Database to write to
Database string
// for serialising
Codec codec.Marshaler
// for locking
Sync sync.Sync
// for storage
Store store.Store
}
type Option func(o *Options)
type ReadOptions struct{}
type ReadOption func(o *ReadOptions)
type DeleteOptions struct{}
type DeleteOption func(o *DeleteOptions)

39
model/options.go Normal file
View File

@ -0,0 +1,39 @@
// Package model is an interface for data modelling
package model
import (
"github.com/unistack-org/micro/v3/codec"
"github.com/unistack-org/micro/v3/logger"
"github.com/unistack-org/micro/v3/store"
"github.com/unistack-org/micro/v3/sync"
)
type Options struct {
// Database to write to
Database string
// for serialising
Codec codec.Marshaler
// for locking
Sync sync.Sync
// for storage
Store store.Store
// for logger
Logger logger.Logger
}
type Option func(o *Options)
// Logger sets the logger
func Logger(l logger.Logger) Option {
return func(o *Options) {
o.Logger = l
}
}
type ReadOptions struct{}
type ReadOption func(o *ReadOptions)
type DeleteOptions struct{}
type DeleteOption func(o *DeleteOptions)