Skip to content

Commit

Permalink
feat: plugin v3
Browse files Browse the repository at this point in the history
Signed-off-by: Valery Piashchynski <[email protected]>
  • Loading branch information
rustatian committed Oct 13, 2022
1 parent 819da3b commit ab9ac86
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ jobs:
- name: Run linter
uses: golangci/[email protected] # Action page: <https://github.com/golangci/golangci-lint-action>
with:
version: v1.49 # without patch version
version: v1.50 # without patch version
only-new-issues: false # show only new issues if it's a pull request
args: --timeout=10m --build-tags=race
2 changes: 0 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Documentation: <https://github.com/golangci/golangci-lint#config-file>

run:
go: '1.17'
timeout: 1m
skip-dirs:
- .github
Expand Down Expand Up @@ -68,7 +67,6 @@ linters: # All available linters list: <https://golangci-lint.run/usage/linters/
- noctx # finds sending http request without context.Context
- nolintlint # Reports ill-formed or insufficient nolint directives
- prealloc # Finds slice declarations that could potentially be preallocated
- rowserrcheck # Checks whether Err of rows is checked successfully
- staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks
- stylecheck # Stylecheck is a replacement for golint
- tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# memcached
RRv2 memcached plugin
# Docs: [link](https://roadrunner.dev)
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module github.com/roadrunner-server/memcached/v2
module github.com/roadrunner-server/memcached/v3

go 1.19

require (
github.com/bradfitz/gomemcache v0.0.0-20220106215444-fb4bf637b56d
github.com/roadrunner-server/api/v2 v2.23.0
github.com/roadrunner-server/errors v1.2.0
github.com/roadrunner-server/sdk/v3 v3.0.0-beta.4
go.buf.build/protocolbuffers/go/roadrunner-server/api v1.3.12
go.uber.org/zap v1.23.0
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/roadrunner-server/api/v2 v2.23.0 h1:FCpVZWl7fZZqBdD/Z4HCVgQ+vKbqARneji20mp3iqDM=
github.com/roadrunner-server/api/v2 v2.23.0/go.mod h1:UrOUfDFw0927h/PWv7f8PPcwfdHkwf8txWbmqszL7UA=
github.com/roadrunner-server/errors v1.2.0 h1:qBmNXt8Iex9QnYTjCkbJKsBZu2EtYkQCM06GUDcQBbI=
github.com/roadrunner-server/errors v1.2.0/go.mod h1:z0ECxZp/dDa5RahtMcy4mBIavVxiZ9vwE5kByl7kFtY=
github.com/roadrunner-server/sdk/v3 v3.0.0-beta.4 h1:jrBpY72kXYTkfQ00RME2HaW/m9+L4jYLujdkhW2/uwE=
github.com/roadrunner-server/sdk/v3 v3.0.0-beta.4/go.mod h1:QnhQ/Ib3uYXSVF0N9F7Accozx/nLkvRdGgufOJq5WfA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
Expand Down
10 changes: 8 additions & 2 deletions memcachedkv/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ import (
"time"

"github.com/bradfitz/gomemcache/memcache"
"github.com/roadrunner-server/api/v2/plugins/config"
"github.com/roadrunner-server/errors"
kvv1 "go.buf.build/protocolbuffers/go/roadrunner-server/api/proto/kv/v1"
"go.uber.org/zap"
)

type Configurer interface {
// UnmarshalKey takes a single key and unmarshal it into a Struct.
UnmarshalKey(name string, out any) error
// Has checks if config section exists.
Has(name string) bool
}

type Driver struct {
client *memcache.Client
log *zap.Logger
Expand All @@ -21,7 +27,7 @@ type Driver struct {
// NewMemcachedDriver returns a memcache client using the provided server(s)
// with equal weight. If a server is listed multiple times,
// it gets a proportional amount of weight.
func NewMemcachedDriver(log *zap.Logger, key string, cfgPlugin config.Configurer) (*Driver, error) {
func NewMemcachedDriver(log *zap.Logger, key string, cfgPlugin Configurer) (*Driver, error) {
const op = errors.Op("new_memcached_driver")

s := &Driver{
Expand Down
16 changes: 11 additions & 5 deletions plugin.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package memcached

import (
"github.com/roadrunner-server/api/v2/plugins/config"
"github.com/roadrunner-server/api/v2/plugins/kv"
"github.com/roadrunner-server/errors"
"github.com/roadrunner-server/memcached/v2/memcachedkv"
"github.com/roadrunner-server/memcached/v3/memcachedkv"
"github.com/roadrunner-server/sdk/v3/plugins/kv"
"go.uber.org/zap"
)

Expand All @@ -13,14 +12,21 @@ const (
RootPluginName string = "kv"
)

type Configurer interface {
// UnmarshalKey takes a single key and unmarshal it into a Struct.
UnmarshalKey(name string, out any) error
// Has checks if config section exists.
Has(name string) bool
}

type Plugin struct {
// config plugin
cfgPlugin config.Configurer
cfgPlugin Configurer
// logger
log *zap.Logger
}

func (p *Plugin) Init(log *zap.Logger, cfg config.Configurer) error {
func (p *Plugin) Init(log *zap.Logger, cfg Configurer) error {
if !cfg.Has(RootPluginName) {
return errors.E(errors.Disabled)
}
Expand Down

0 comments on commit ab9ac86

Please sign in to comment.