From 3de132e2248fa8257f5e0dc2aa688bff8f94418c Mon Sep 17 00:00:00 2001 From: saltbo Date: Mon, 25 Jan 2021 23:34:38 +0800 Subject: [PATCH] feat: add rootpath filepath publicread --- model/storage.go | 30 ++++++++++++++++-------------- rest/bind/storage.go | 22 +++++++++++++++------- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/model/storage.go b/model/storage.go index 0d5ba8f..9248703 100644 --- a/model/storage.go +++ b/model/storage.go @@ -9,20 +9,22 @@ const ( ) type Storage struct { - Id int64 `json:"id"` - Mode int8 `json:"mode" gorm:"size:16;not null"` - Name string `json:"name" gorm:"size:16;not null"` - Title string `json:"title" gorm:"size:16;not null"` - Bucket string `json:"bucket" gorm:"size:32;not null"` - Provider string `json:"provider" gorm:"size:8;not null"` - Endpoint string `json:"endpoint" gorm:"size:128;not null"` - AccessKey string `json:"access_key" gorm:"size:64;not null"` - SecretKey string `json:"secret_key" gorm:"size:64;not null"` - CustomHost string `json:"custom_host" gorm:"size:128;not null"` - ObjectPattern string `json:"object_pattern" gorm:"size:64;not null"` - Created time.Time `json:"created" gorm:"column:created_at;not null"` - Updated time.Time `json:"updated" gorm:"column:updated_at;not null"` - Deleted *time.Time `json:"-" gorm:"column:deleted_at"` + Id int64 `json:"id"` + Mode int8 `json:"mode" gorm:"size:16;not null"` + Name string `json:"name" gorm:"size:16;not null"` + Title string `json:"title" gorm:"size:16;not null"` + Bucket string `json:"bucket" gorm:"size:32;not null"` + Provider string `json:"provider" gorm:"size:8;not null"` + Endpoint string `json:"endpoint" gorm:"size:128;not null"` + AccessKey string `json:"access_key" gorm:"size:64;not null"` + SecretKey string `json:"secret_key" gorm:"size:64;not null"` + CustomHost string `json:"custom_host" gorm:"size:128;not null"` + RootPath string `json:"root_path" gorm:"size:64;not null"` + FilePath string `json:"file_path" gorm:"size:1024;not null"` + PublicRead bool `json:"public_read" gorm:"size:1;not null"` + Created time.Time `json:"created" gorm:"column:created_at;not null"` + Updated time.Time `json:"updated" gorm:"column:updated_at;not null"` + Deleted *time.Time `json:"-" gorm:"column:deleted_at"` } func (Storage) TableName() string { diff --git a/rest/bind/storage.go b/rest/bind/storage.go index 7e5c244..1f61cd1 100644 --- a/rest/bind/storage.go +++ b/rest/bind/storage.go @@ -6,6 +6,8 @@ import ( "github.com/saltbo/zpan/model" ) +var ts = strings.TrimSpace + type StorageBody struct { Mode int8 `json:"mode" binding:"required"` Name string `json:"name" binding:"required"` @@ -16,19 +18,25 @@ type StorageBody struct { AccessKey string `json:"access_key" binding:"required"` SecretKey string `json:"secret_key" binding:"required"` CustomHost string `json:"custom_host"` + RootPath string `json:"root_path"` + FilePath string `json:"file_path"` + PublicRead bool `json:"public_read"` } func (b *StorageBody) Model() *model.Storage { return &model.Storage{ Mode: b.Mode, - Name: strings.TrimSpace(b.Name), - Title: strings.TrimSpace(b.Title), - Bucket: strings.TrimSpace(b.Bucket), + Name: ts(b.Name), + Title: ts(b.Title), + Bucket: ts(b.Bucket), Provider: b.Provider, - Endpoint: strings.TrimSpace(b.Endpoint), - CustomHost: strings.TrimSpace(b.CustomHost), - AccessKey: strings.TrimSpace(b.AccessKey), - SecretKey: strings.TrimSpace(b.SecretKey), + Endpoint: ts(b.Endpoint), + CustomHost: ts(b.CustomHost), + AccessKey: ts(b.AccessKey), + SecretKey: ts(b.SecretKey), + RootPath: ts(b.RootPath), + FilePath: ts(b.FilePath), + PublicRead: b.PublicRead, } }