use go-micro store

This commit is contained in:
A.Unger
2020-07-14 13:47:33 +02:00
parent cb719cf892
commit fb74cd49b5
3 changed files with 72 additions and 0 deletions

58
pkg/command/store.go Normal file
View File

@@ -0,0 +1,58 @@
// +build !simple
package command
import (
"context"
"strings"
"time"
"github.com/micro/cli/v2"
"github.com/micro/go-micro/v2"
gostore "github.com/micro/go-micro/v2/store"
"github.com/micro/go-micro/v2/store/file"
"github.com/owncloud/ocis-ocs/pkg/flagset"
"github.com/owncloud/ocis/pkg/config"
"github.com/owncloud/ocis/pkg/register"
)
// StoreCommand is the entrypoint for the ocs command.
func StoreCommand(cfg *config.Config) *cli.Command {
return &cli.Command{
Name: "store",
Usage: "Start a go-micro store",
Category: "Runtime",
Flags: flagset.ServerWithConfig(cfg.OCS),
Action: func(ctx *cli.Context) error {
file.DefaultDir = "/var/tmp/ocis/store"
store := file.NewStore(
gostore.Database("ocis"),
gostore.Table("ocis"),
gostore.WithContext(context.Background()),
)
mopts := []micro.Option{
micro.Name(
strings.Join(
[]string{
"com.owncloud",
"store",
},
".",
),
),
micro.RegisterTTL(time.Second * 30),
micro.RegisterInterval(time.Second * 10),
micro.Store(store),
}
service := micro.NewService(mopts...)
service.Init()
return service.Run()
},
}
}
func init() {
register.AddCommand(StoreCommand)
}