From 32dc837e0558ae56664a83a273e604360cb78621 Mon Sep 17 00:00:00 2001 From: Danis Kirasirov <dbgbbu@gmail.com> Date: Wed, 31 Jan 2024 13:56:42 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D1=82=D0=B5=D0=B3=D0=B0?= =?UTF-8?q?=20expr=20=D0=B2=D0=BC=D0=B5=D1=81=D1=82=D0=BE=20=D0=B8=D0=BD?= =?UTF-8?q?=D1=82=D0=B5=D1=80=D1=84=D0=B5=D0=B9=D1=81=D0=B0=20Mapper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/expr/expr.go | 9 --------- pkg/files/file.go | 23 ++++++----------------- pkg/references/reference.go | 13 +++---------- 3 files changed, 9 insertions(+), 36 deletions(-) diff --git a/pkg/expr/expr.go b/pkg/expr/expr.go index 3f346889..1969b58c 100644 --- a/pkg/expr/expr.go +++ b/pkg/expr/expr.go @@ -31,11 +31,6 @@ func Eval(ctx context.Context, input string, env map[string]interface{}) (interf } for k, v := range env { - if mapper, ok := v.(Mapper); ok { - e[k] = mapper.ToMap() - continue - } - e[k] = v } @@ -83,8 +78,4 @@ func IsExpression(input string) bool { } return false -} - -type Mapper interface { - ToMap() map[string]interface{} } \ No newline at end of file diff --git a/pkg/files/file.go b/pkg/files/file.go index fc12151b..5700309d 100644 --- a/pkg/files/file.go +++ b/pkg/files/file.go @@ -16,12 +16,12 @@ const ( // File - описание файла РІ системе хранения perxis type File struct { - ID string `mapstructure:"id,omitempty" json:"id"` // Уникальный идентификатор файла РІ хранилище - Name string `mapstructure:"name,omitempty" json:"name" bson:"name,omitempty"` // РРјСЏ файла - Size int `mapstructure:"size,omitempty" json:"size" bson:"size,omitempty"` // Размер файла - MimeType string `mapstructure:"mimeType,omitempty" json:"mimeType" bson:"mimeType,omitempty"` // Mime-type файла - URL string `mapstructure:"url,omitempty" json:"url" bson:"url,omitempty"` // Адрес для загрузки файла - Key string `mapstructure:"key,omitempty" json:"key" bson:"key,omitempty"` // Ключ для хранения файла РІ хранилище + ID string `mapstructure:"id,omitempty" json:"id" expr:"id"` // Уникальный идентификатор файла РІ хранилище + Name string `mapstructure:"name,omitempty" json:"name" bson:"name,omitempty" expr:"name"` // РРјСЏ файла + Size int `mapstructure:"size,omitempty" json:"size" bson:"size,omitempty" expr:"size"` // Размер файла + MimeType string `mapstructure:"mimeType,omitempty" json:"mimeType" bson:"mimeType,omitempty" expr:"mime_type"` // Mime-type файла + URL string `mapstructure:"url,omitempty" json:"url" bson:"url,omitempty" expr:"url"` // Адрес для загрузки файла + Key string `mapstructure:"key,omitempty" json:"key" bson:"key,omitempty" expr:"key"` // Ключ для хранения файла РІ хранилище File fs.File `mapstructure:"-" json:"-" bson:"-"` // Файл для загрузки(РёР· файловой системы) } @@ -47,17 +47,6 @@ func (f *File) SetURLWithTemplate(t *template.Template) error { return nil } -func (f File) ToMap() map[string]interface{} { - return map[string]interface{}{ - "id": f.ID, - "name": f.Name, - "size": f.Size, - "mime_type": f.MimeType, - "url": f.URL, - "key": f.Key, - } -} - func NewFile(name, mimeType string, size int, temp bool) *File { i := id.GenerateNewID() if temp { diff --git a/pkg/references/reference.go b/pkg/references/reference.go index b1b56953..171ded42 100644 --- a/pkg/references/reference.go +++ b/pkg/references/reference.go @@ -7,9 +7,9 @@ import ( ) type Reference struct { - ID string `json:"id" bson:"id" mapstructure:"id"` - CollectionID string `json:"collection_id" bson:"collection_id" mapstructure:"collection_id"` - Disabled bool `json:"disabled,omitempty" bson:"disabled,omitempty" mapstructure:"disabled"` + ID string `json:"id" bson:"id" mapstructure:"id" expr:"id"` + CollectionID string `json:"collection_id" bson:"collection_id" mapstructure:"collection_id" expr:"collection_id"` + Disabled bool `json:"disabled,omitempty" bson:"disabled,omitempty" mapstructure:"disabled" expr:"disabled"` } func (r *Reference) MarshalBSON() ([]byte, error) { @@ -25,13 +25,6 @@ func (r *Reference) MarshalBSON() ([]byte, error) { return bson.Marshal(d) } -func (r *Reference) ToMap() map[string]interface{} { - return map[string]interface{}{ - "collection_id": r.CollectionID, - "id": r.ID, - } -} - func ReferenceFromPB(refPB *pb.Reference) *Reference { if refPB == nil { return nil -- GitLab