path management and protobuf redesign

This commit is contained in:
A.Unger
2020-01-31 11:05:47 +01:00
parent 01be15e8fc
commit 673c2c0ebd
4 changed files with 191 additions and 74 deletions
+162 -64
View File
@@ -5,9 +5,8 @@ package proto
import (
fmt "fmt"
math "math"
proto "github.com/golang/protobuf/proto"
math "math"
)
// Reference imports to suppress errors if they are not otherwise used.
@@ -22,11 +21,11 @@ var _ = math.Inf
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
type Record struct {
Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
Payload *Settings `protobuf:"bytes,2,opt,name=payload,proto3" json:"payload,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
Payload *Payload `protobuf:"bytes,2,opt,name=payload,proto3" json:"payload,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Record) Reset() { *m = Record{} }
@@ -61,13 +60,146 @@ func (m *Record) GetKey() string {
return ""
}
func (m *Record) GetPayload() *Settings {
func (m *Record) GetPayload() *Payload {
if m != nil {
return m.Payload
}
return nil
}
type Payload struct {
Phoenix *Phoenix `protobuf:"bytes,1,opt,name=phoenix,proto3" json:"phoenix,omitempty"`
Account *Account `protobuf:"bytes,2,opt,name=account,proto3" json:"account,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Payload) Reset() { *m = Payload{} }
func (m *Payload) String() string { return proto.CompactTextString(m) }
func (*Payload) ProtoMessage() {}
func (*Payload) Descriptor() ([]byte, []int) {
return fileDescriptor_e3c84319968a576b, []int{1}
}
func (m *Payload) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Payload.Unmarshal(m, b)
}
func (m *Payload) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Payload.Marshal(b, m, deterministic)
}
func (m *Payload) XXX_Merge(src proto.Message) {
xxx_messageInfo_Payload.Merge(m, src)
}
func (m *Payload) XXX_Size() int {
return xxx_messageInfo_Payload.Size(m)
}
func (m *Payload) XXX_DiscardUnknown() {
xxx_messageInfo_Payload.DiscardUnknown(m)
}
var xxx_messageInfo_Payload proto.InternalMessageInfo
func (m *Payload) GetPhoenix() *Phoenix {
if m != nil {
return m.Phoenix
}
return nil
}
func (m *Payload) GetAccount() *Account {
if m != nil {
return m.Account
}
return nil
}
type Account struct {
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
DateOfBirth string `protobuf:"bytes,2,opt,name=dateOfBirth,proto3" json:"dateOfBirth,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Account) Reset() { *m = Account{} }
func (m *Account) String() string { return proto.CompactTextString(m) }
func (*Account) ProtoMessage() {}
func (*Account) Descriptor() ([]byte, []int) {
return fileDescriptor_e3c84319968a576b, []int{2}
}
func (m *Account) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Account.Unmarshal(m, b)
}
func (m *Account) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Account.Marshal(b, m, deterministic)
}
func (m *Account) XXX_Merge(src proto.Message) {
xxx_messageInfo_Account.Merge(m, src)
}
func (m *Account) XXX_Size() int {
return xxx_messageInfo_Account.Size(m)
}
func (m *Account) XXX_DiscardUnknown() {
xxx_messageInfo_Account.DiscardUnknown(m)
}
var xxx_messageInfo_Account proto.InternalMessageInfo
func (m *Account) GetName() string {
if m != nil {
return m.Name
}
return ""
}
func (m *Account) GetDateOfBirth() string {
if m != nil {
return m.DateOfBirth
}
return ""
}
type Phoenix struct {
Theme string `protobuf:"bytes,1,opt,name=theme,proto3" json:"theme,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Phoenix) Reset() { *m = Phoenix{} }
func (m *Phoenix) String() string { return proto.CompactTextString(m) }
func (*Phoenix) ProtoMessage() {}
func (*Phoenix) Descriptor() ([]byte, []int) {
return fileDescriptor_e3c84319968a576b, []int{3}
}
func (m *Phoenix) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Phoenix.Unmarshal(m, b)
}
func (m *Phoenix) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Phoenix.Marshal(b, m, deterministic)
}
func (m *Phoenix) XXX_Merge(src proto.Message) {
xxx_messageInfo_Phoenix.Merge(m, src)
}
func (m *Phoenix) XXX_Size() int {
return xxx_messageInfo_Phoenix.Size(m)
}
func (m *Phoenix) XXX_DiscardUnknown() {
xxx_messageInfo_Phoenix.DiscardUnknown(m)
}
var xxx_messageInfo_Phoenix proto.InternalMessageInfo
func (m *Phoenix) GetTheme() string {
if m != nil {
return m.Theme
}
return ""
}
type Query struct {
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
@@ -79,7 +211,7 @@ func (m *Query) Reset() { *m = Query{} }
func (m *Query) String() string { return proto.CompactTextString(m) }
func (*Query) ProtoMessage() {}
func (*Query) Descriptor() ([]byte, []int) {
return fileDescriptor_e3c84319968a576b, []int{1}
return fileDescriptor_e3c84319968a576b, []int{4}
}
func (m *Query) XXX_Unmarshal(b []byte) error {
@@ -107,67 +239,33 @@ func (m *Query) GetId() string {
return ""
}
type Settings struct {
Theme string `protobuf:"bytes,2,opt,name=theme,proto3" json:"theme,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Settings) Reset() { *m = Settings{} }
func (m *Settings) String() string { return proto.CompactTextString(m) }
func (*Settings) ProtoMessage() {}
func (*Settings) Descriptor() ([]byte, []int) {
return fileDescriptor_e3c84319968a576b, []int{2}
}
func (m *Settings) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Settings.Unmarshal(m, b)
}
func (m *Settings) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Settings.Marshal(b, m, deterministic)
}
func (m *Settings) XXX_Merge(src proto.Message) {
xxx_messageInfo_Settings.Merge(m, src)
}
func (m *Settings) XXX_Size() int {
return xxx_messageInfo_Settings.Size(m)
}
func (m *Settings) XXX_DiscardUnknown() {
xxx_messageInfo_Settings.DiscardUnknown(m)
}
var xxx_messageInfo_Settings proto.InternalMessageInfo
func (m *Settings) GetTheme() string {
if m != nil {
return m.Theme
}
return ""
}
func init() {
proto.RegisterType((*Record)(nil), "settings.Record")
proto.RegisterType((*Payload)(nil), "settings.Payload")
proto.RegisterType((*Account)(nil), "settings.Account")
proto.RegisterType((*Phoenix)(nil), "settings.Phoenix")
proto.RegisterType((*Query)(nil), "settings.Query")
proto.RegisterType((*Settings)(nil), "settings.Settings")
}
func init() { proto.RegisterFile("pkg/proto/v0/accounts.proto", fileDescriptor_e3c84319968a576b) }
var fileDescriptor_e3c84319968a576b = []byte{
// 211 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2e, 0xc8, 0x4e, 0xd7,
0x2f, 0x28, 0xca, 0x2f, 0xc9, 0xd7, 0x2f, 0x33, 0xd0, 0x4f, 0x4c, 0x4e, 0xce, 0x2f, 0xcd, 0x2b,
0x29, 0xd6, 0x03, 0x8b, 0x08, 0x71, 0x14, 0xa7, 0x96, 0x94, 0x64, 0xe6, 0xa5, 0x17, 0x2b, 0x79,
0x70, 0xb1, 0x05, 0xa5, 0x26, 0xe7, 0x17, 0xa5, 0x08, 0x09, 0x70, 0x31, 0x67, 0xa7, 0x56, 0x4a,
0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0x81, 0x98, 0x42, 0x3a, 0x5c, 0xec, 0x05, 0x89, 0x95, 0x39,
0xf9, 0x89, 0x29, 0x12, 0x4c, 0x0a, 0x8c, 0x1a, 0xdc, 0x46, 0x42, 0x7a, 0x30, 0x7d, 0x7a, 0xc1,
0x50, 0x46, 0x10, 0x4c, 0x89, 0x92, 0x38, 0x17, 0x6b, 0x60, 0x69, 0x6a, 0x51, 0xa5, 0x10, 0x1f,
0x17, 0x53, 0x66, 0x0a, 0xd4, 0x1c, 0xa6, 0xcc, 0x14, 0x25, 0x05, 0x2e, 0x0e, 0x98, 0x6a, 0x21,
0x11, 0x2e, 0xd6, 0x92, 0x8c, 0xd4, 0xdc, 0x54, 0xb0, 0x81, 0x9c, 0x41, 0x10, 0x8e, 0x51, 0x1a,
0x17, 0x3f, 0x4c, 0x45, 0x70, 0x6a, 0x51, 0x59, 0x66, 0x72, 0xaa, 0x90, 0x26, 0x17, 0x73, 0x70,
0x6a, 0x89, 0x90, 0x00, 0xc2, 0x46, 0x88, 0x33, 0xa5, 0x30, 0x44, 0x84, 0x34, 0xb8, 0x98, 0xdd,
0x53, 0x4b, 0x84, 0xf8, 0x11, 0x12, 0x60, 0x77, 0x60, 0xaa, 0x74, 0x62, 0x8f, 0x62, 0x05, 0xfb,
0x3f, 0x89, 0x0d, 0x4c, 0x19, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x28, 0x61, 0x84, 0x13, 0x25,
0x01, 0x00, 0x00,
// 271 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0x51, 0x4f, 0x4f, 0x83, 0x30,
0x14, 0x0f, 0x20, 0xc3, 0xbd, 0x25, 0x6e, 0xbe, 0x98, 0xb8, 0xe8, 0x41, 0xc2, 0x09, 0x63, 0x02,
0x66, 0x7e, 0x00, 0xe3, 0x2e, 0x3b, 0xaa, 0xe5, 0xe6, 0x0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, 0x1d, 0x0b, 0x9b, 0xa7, 0xbc, 0x19, 0x20, 0x18, 0x83, 0xb7, 0x22,
0x85, 0xd3, 0x23, 0xa1, 0xb7, 0x0c, 0x95, 0xcb, 0xe0, 0xc3, 0xd7, 0x7f, 0xf4, 0x39, 0xd2, 0xc7,
0xd3, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x66, 0x19, 0xd7, 0xce, 0xc9, 0x01, 0x00, 0x00,
}
+13 -3
View File
@@ -10,11 +10,21 @@ service SettingsService {
message Record {
string key = 1;
Settings payload = 2;
Payload payload = 2;
}
message Settings {
string theme = 2;
message Payload {
Phoenix phoenix = 1;
Account account = 2;
}
message Account {
string name = 1;
string dateOfBirth = 2;
}
message Phoenix {
string theme = 1;
}
message Query {
+2 -1
View File
@@ -23,7 +23,8 @@ func (s Service) Set(c context.Context, req *proto.Record, res *proto.Record) er
settingsJSON, err := json.Marshal(req.Payload)
if err != nil {
// TODO deal with this
// TODO log the error
return err
}
record := mstore.Record{
+14 -6
View File
@@ -4,20 +4,24 @@ package store
import (
"fmt"
"io/ioutil"
"path/filepath"
mstore "github.com/micro/go-micro/v2/store"
)
// DefaultPath assumes UNIX
var DefaultPath string = "/var/tmp/ocis-store"
// Store interacts with the filesystem to manage account information
type Store struct {
mountPath string
}
// New returns a new file system store manager
// TODO add mountPath as an option argument
// TODO add mountPath as a flag
func New() Store {
return Store{
mountPath: "/var/tmp/ocis-store",
mountPath: DefaultPath,
}
}
@@ -36,14 +40,18 @@ func (s *Store) Read(key string, opts ...mstore.ReadOption) ([]*mstore.Record, e
// Write implements the store interface
func (s *Store) Write(rec *mstore.Record) error {
path := filepath.Join(s.mountPath, rec.Key)
if filepath.IsAbs(path) {
// TODO WARN, storage is relative to the service directory
}
if len(rec.Key) < 1 {
// TODO log error: empty key
return fmt.Errorf("%v", "key is empty")
}
if err := ioutil.WriteFile(s.mountPath+"/"+rec.Key, rec.Value, 0644); err != nil {
// TODO handle error
}
return nil
return ioutil.WriteFile(path, rec.Value, 0644)
}
// Delete implements the store interface