set database/table in header

This commit is contained in:
Asim Aslam 2020-04-08 19:25:57 +01:00
parent 48dd30c4c2
commit 45700eaabe

View File

@ -16,18 +16,15 @@ import (
type serviceStore struct { type serviceStore struct {
options store.Options options store.Options
// Namespace to use // The database to use
Namespace string Database string
// The table to use
Table string
// Addresses of the nodes // Addresses of the nodes
Nodes []string Nodes []string
// Prefix to use
Prefix string
// Suffix to use
Suffix string
// store service client // store service client
Client pb.StoreService Client pb.StoreService
} }
@ -40,8 +37,8 @@ func (s *serviceStore) Init(opts ...store.Option) error {
for _, o := range opts { for _, o := range opts {
o(&s.options) o(&s.options)
} }
s.Namespace = s.options.Database s.Database = s.options.Database
s.Prefix = s.options.Table s.Table = s.options.Table
s.Nodes = s.options.Nodes s.Nodes = s.options.Nodes
return nil return nil
@ -52,12 +49,12 @@ func (s *serviceStore) Context() context.Context {
md := make(metadata.Metadata) md := make(metadata.Metadata)
if len(s.Namespace) > 0 { if len(s.Database) > 0 {
md["Micro-Namespace"] = s.Namespace md["Micro-Database"] = s.Database
} }
if len(s.Prefix) > 0 { if len(s.Table) > 0 {
md["Micro-Prefix"] = s.Prefix md["Micro-Table"] = s.Table
} }
return metadata.NewContext(ctx, md) return metadata.NewContext(ctx, md)
@ -168,11 +165,11 @@ func NewStore(opts ...store.Option) store.Store {
} }
service := &serviceStore{ service := &serviceStore{
options: options, options: options,
Namespace: options.Database, Database: options.Database,
Prefix: options.Table, Table: options.Table,
Nodes: options.Nodes, Nodes: options.Nodes,
Client: pb.NewStoreService("go.micro.store", client.DefaultClient), Client: pb.NewStoreService("go.micro.store", client.DefaultClient),
} }
return service return service