diff --git a/.zpan.yaml b/.zpan.yaml index ad77a47..d91641b 100644 --- a/.zpan.yaml +++ b/.zpan.yaml @@ -1,10 +1,12 @@ -host: http://local.frpx.saltbo.cn:1080 -mysqldsn: root:admin@tcp(127.0.0.1:3306)/zpan?charset=utf8&interpolateParams=true +siteHost: http://inlets.saltbo.cn +database: + driver: mysql + dsn: root:admin@tcp(127.0.0.1:3306)/zpan?charset=utf8&parseTime=True&loc=Local provider: name: alioss bucket: saltbo-zpan-test endpoint: https://oss-cn-zhangjiakou.aliyuncs.com - access_key: LTAI4FxxxxxxxxxxxxBXmS3 - access_secret: Vt1FZgXxxxxxxxxxxxxxxx380AI + accessKey: LTAI4FxxxxxxxxxxxxBXmS3 + accessSecret: Vt1FZgXxxxxxxxxxxxxxxx380AI diff --git a/cmd/root.go b/cmd/root.go index 9b3fb7c..a1dfb77 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -36,7 +36,7 @@ var cfgFile string // rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ Use: "zpan", - Short: "zpan is a cloud disk base on the cloud storage.", + Short: "zpan is a cloud disk base on the cloud service.", Long: `Zpan is a cloud disk server built with love by saltbo and friends in Go. diff --git a/cmd/server.go b/cmd/server.go index 6e57bc2..e894999 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -22,39 +22,43 @@ THE SOFTWARE. package cmd import ( + "fmt" "log" "github.com/saltbo/gopkg/ginutil" + "github.com/saltbo/gopkg/gormutil" "github.com/spf13/cobra" "github.com/saltbo/zpan/config" - "github.com/saltbo/zpan/dao" "github.com/saltbo/zpan/disk" + "github.com/saltbo/zpan/model" "github.com/saltbo/zpan/rest" ) // serverCmd represents the server command var serverCmd = &cobra.Command{ Use: "server", - Short: "A cloud disk base on the cloud storage.", + Short: "A cloud disk base on the cloud service.", Run: func(cmd *cobra.Command, args []string) { conf := config.Parse() - dao.Init(conf.MySqlDSN) - rs, err := ginutil.NewServer(":8222") - if err != nil { - log.Fatalln(err) - } + gormutil.Init(conf.Database, + &model.Matter{}, + &model.Share{}, + &model.Storage{}, + ) + fmt.Println(conf.Provider) diskProvider, err := disk.New(conf.Provider) if err != nil { log.Fatalln(err) } - rs.SetupResource("/api", + rs := ginutil.NewServer(":8222") + rs.SetupGroupRS("/api", rest.NewFileResource(conf.Provider.Bucket, diskProvider), rest.NewShareResource(), rest.NewURLResource(conf, diskProvider), - rest.NewUserResource(), + rest.NewStorageResource(), ) if err := rs.Run(); err != nil { log.Fatal(err) diff --git a/config/config.go b/config/config.go index 1b1c00d..83c61e1 100644 --- a/config/config.go +++ b/config/config.go @@ -3,23 +3,24 @@ package config import ( "log" + "github.com/saltbo/gopkg/gormutil" "github.com/spf13/viper" ) // CloudProvider type Provider struct { - Name string `yaml:"name"` - Bucket string `yaml:"bucket"` - Endpoint string `yaml:"endpoint"` - AccessKey string `yaml:"access_key"` - AccessSecret string `yaml:"access_secret"` + Name string + Bucket string + Endpoint string + AccessKey string + AccessSecret string } type Config struct { - SiteHost string `yaml:"site_host"` - StoreHost string `yaml:"store_host"` - MySqlDSN string `yaml:"mysqldsn"` - Provider *Provider `yaml:"provider"` + SiteHost string + StoreHost string + Database gormutil.Config + Provider *Provider } func Parse() *Config { diff --git a/dao/db.go b/dao/db.go deleted file mode 100644 index 152a991..0000000 --- a/dao/db.go +++ /dev/null @@ -1,31 +0,0 @@ -package dao - -import ( - "log" - - "github.com/saltbo/zpan/model" - - _ "github.com/go-sql-driver/mysql" - "github.com/go-xorm/xorm" -) - -var DB *xorm.Engine - -func Init(dsn string) { - db, err := xorm.NewEngine("mysql", dsn) - if err != nil { - log.Fatalln(err) - } - db.ShowSQL(true) - - models := []interface{}{ - new(model.User), - new(model.Share), - new(model.Matter), - } - if err := db.Sync2(models...); err != nil { - log.Fatalln(err) - } - - DB = db -} diff --git a/dao/matter.go b/dao/matter.go deleted file mode 100644 index 15985e1..0000000 --- a/dao/matter.go +++ /dev/null @@ -1,92 +0,0 @@ -package dao - -import ( - "fmt" - "log" - "strings" - - "github.com/saltbo/zpan/model" -) - -func DirExist(uid int64, dir string) bool { - if dir == "" { - return true - } - - items := strings.Split(dir, "/") - name := items[len(items)-2] - parent := strings.TrimSuffix(dir, name+"/") - exist, err := DB.Where("uid=? and name=? and parent=?", uid, name, parent).Exist(&model.Matter{}) - if err != nil { - log.Panicln(err) - } - - return exist -} - -func FileGet(uid int64, fileId interface{}) (*model.Matter, error) { - m := new(model.Matter) - if exist, err := DB.Id(fileId).Get(m); err != nil { - return nil, err - } else if !exist { - return nil, fmt.Errorf("file not exist.") - } else if m.Uid != uid { - return nil, fmt.Errorf("file not belong to you.") - } - - return m, nil -} - -func FileCopy(srcFile *model.Matter, dest string) error { - m := &model.Matter{ - Uid: srcFile.Uid, - Name: srcFile.Name, - Type: srcFile.Type, - Size: srcFile.Size, - Parent: dest, - Object: srcFile.Object, - } - _, err := DB.Insert(m) - return err -} - -func FileMove(id int64, dest string) error { - _, err := DB.ID(id).Cols("parent").Update(&model.Matter{Parent: dest}) - return err -} - -func FileRename(id int64, name string) error { - _, err := DB.ID(id).Cols("name").Update(&model.Matter{Name: name}) - return err -} - -func DirRename(id int64, name string) error { - oldMatter := new(model.Matter) - if exist, _ := DB.Id(id).Get(oldMatter); !exist { - return fmt.Errorf("matter not exist.") - } - - oldParent := fmt.Sprintf("%s%s/", oldMatter.Parent, oldMatter.Name) - newParent := fmt.Sprintf("%s%s/", oldMatter.Parent, name) - list := make([]model.Matter, 0) - _ = DB.Where("parent like '" + oldParent + "%'").Find(&list) - - session := DB.NewSession() - defer session.Close() - for _, v := range list { - v.Parent = strings.Replace(v.Parent, oldParent, newParent, 1) - _, err := session.ID(v.Id).Cols("parent").Update(v) - if err != nil { - _ = session.Rollback() - return err - } - } - - m := &model.Matter{Name: name} - if _, err := session.ID(id).Cols("name").Update(m); err != nil { - _ = session.Rollback() - return err - } - - return session.Commit() -} diff --git a/go.mod b/go.mod index 20b56f5..0815875 100644 --- a/go.mod +++ b/go.mod @@ -5,10 +5,9 @@ go 1.14 require ( github.com/aliyun/aliyun-oss-go-sdk v2.1.4+incompatible github.com/gin-gonic/gin v1.6.3 - github.com/go-sql-driver/mysql v1.5.0 - github.com/go-xorm/xorm v0.7.9 + github.com/jinzhu/gorm v1.9.16 github.com/mitchellh/go-homedir v1.1.0 - github.com/saltbo/gopkg v0.0.0-20200806124254-1f4fecb05e7c + github.com/saltbo/gopkg v0.0.0-20200817013558-116ba552a859 github.com/satori/go.uuid v1.2.0 github.com/spf13/cobra v1.0.0 github.com/spf13/viper v1.7.1 diff --git a/go.sum b/go.sum index fa47361..edf1ec7 100644 --- a/go.sum +++ b/go.sum @@ -15,11 +15,19 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7 github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= +github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc= +github.com/PuerkitoBio/purell v1.1.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= +github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI= +github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= +github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M= +github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/aliyun/aliyun-oss-go-sdk v1.9.8 h1:BOflvK0Zs/zGmoabyFIzTg5c3kguktWTXEwewwbuba0= github.com/aliyun/aliyun-oss-go-sdk v2.1.4+incompatible h1:6t4QUhWVCcnilQy+d3aO0zsaO7wH6N3geMo4wgbC4MY= @@ -47,6 +55,7 @@ github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3Ee github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= +github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -66,14 +75,38 @@ github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/gin-contrib/gzip v0.0.1/go.mod h1:fGBJBCdt6qCZuCAOwWuFhBB4OOq9EFqlo5dEaFhhu5w= +github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s= +github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= +github.com/gin-gonic/gin v1.3.0/go.mod h1:7cKuhb5qV2ggCFctp2fJQ+ErvciLZrIeoOSOm6mUr7Y= +github.com/gin-gonic/gin v1.4.0/go.mod h1:OW2EZn3DO8Ln9oIKOvM++LBO+5UPHJJDH72/q/3rZdM= github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14= github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-openapi/jsonpointer v0.17.0/go.mod h1:cOnomiV+CVVwFLk0A/MExoFMjwdsUdVpsRhURCKh+3M= +github.com/go-openapi/jsonpointer v0.19.2/go.mod h1:3akKfEdA7DF1sugOqz1dVQHBcuDBPKZGEoHC/NkiQRg= +github.com/go-openapi/jsonpointer v0.19.3 h1:gihV7YNZK1iK6Tgwwsxo2rJbD1GTbdm72325Bq8FI3w= +github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= +github.com/go-openapi/jsonreference v0.17.0/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3HfopLOL6uZrK/VgnsK9I= +github.com/go-openapi/jsonreference v0.19.0/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3HfopLOL6uZrK/VgnsK9I= +github.com/go-openapi/jsonreference v0.19.2/go.mod h1:jMjeRr2HHw6nAVajTXJ4eiUwohSTlpa0o73RUL1owJc= +github.com/go-openapi/jsonreference v0.19.3/go.mod h1:rjx6GuL8TTa9VaixXglHmQmIL98+wF9xc8zWvFonSJ8= +github.com/go-openapi/jsonreference v0.19.4 h1:3Vw+rh13uq2JFNxgnMTGE1rnoieU9FmyE1gvnyylsYg= +github.com/go-openapi/jsonreference v0.19.4/go.mod h1:RdybgQwPxbL4UEjuAruzK1x3nE69AqPYEJeo/TWfEeg= +github.com/go-openapi/spec v0.19.0/go.mod h1:XkF/MOi14NmjsfZ8VtAKf8pIlbZzyoTvZsdfssdxcBI= +github.com/go-openapi/spec v0.19.4/go.mod h1:FpwSN1ksY1eteniUU7X0N/BgJ7a4WvBFVA8Lj9mJglo= +github.com/go-openapi/spec v0.19.9 h1:9z9cbFuZJ7AcvOHKIY+f6Aevb4vObNDkTEyoMfO7rAc= +github.com/go-openapi/spec v0.19.9/go.mod h1:vqK/dIdLGCosfvYsQV3WfC7N3TiZSnGY2RZKoFK7X28= +github.com/go-openapi/swag v0.17.0/go.mod h1:AByQ+nYG6gQg71GINrmuDXCPWdL640yX49/kXLo40Tg= +github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= +github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= +github.com/go-openapi/swag v0.19.9 h1:1IxuqvBUU3S2Bi4YC7tlP9SJF1gVpCvqN0T2Qof4azE= +github.com/go-openapi/swag v0.19.9/go.mod h1:ao+8BpOPyKdpQz3AOJfbeEVpLmWAvlT1IfTe5McPyhY= github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A= github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= @@ -170,10 +203,15 @@ github.com/jackc/fake v0.0.0-20150926172116-812a484cc733/go.mod h1:WrMFNQdiFJ80s github.com/jackc/pgx v3.6.0+incompatible/go.mod h1:0ZGrqGqkRlliWnWB4zKnWtjbSWbGkVEFm4TeybAXq+I= github.com/jinzhu/gorm v1.9.15 h1:OdR1qFvtXktlxk73XFYMiYn9ywzTwytqe4QkuMRqc38= github.com/jinzhu/gorm v1.9.15/go.mod h1:G3LB3wezTOWM2ITLzPxEXgSkOXAntiLHS7UdBefADcs= +github.com/jinzhu/gorm v1.9.16 h1:+IyIjPEABKRpsu/F8OvDPy9fyQlgsg2luMV2ZIH5i5o= +github.com/jinzhu/gorm v1.9.16/go.mod h1:G3LB3wezTOWM2ITLzPxEXgSkOXAntiLHS7UdBefADcs= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= github.com/jinzhu/now v1.0.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= +github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= +github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= +github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= @@ -189,6 +227,7 @@ github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFB github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= @@ -200,8 +239,16 @@ github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDe github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mailru/easyjson v0.7.2 h1:V9ecaZWDYm7v9uJ15RZD6DajMu5sE0hdep0aoDwT9g4= +github.com/mailru/easyjson v0.7.2/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= @@ -269,6 +316,10 @@ github.com/saltbo/gopkg v0.0.0-20200805142521-0f999bd67f80 h1:8THMNe3rzdVXcdGuFl github.com/saltbo/gopkg v0.0.0-20200805142521-0f999bd67f80/go.mod h1:/6/9WzUMdFS1vpASkEoEleG7jM8/eHU3pRJc+w4kDhU= github.com/saltbo/gopkg v0.0.0-20200806124254-1f4fecb05e7c h1:BYyMFkrmjI1ylQOe/QleN4wY2kC2N6zcUo4gKyRNUCI= github.com/saltbo/gopkg v0.0.0-20200806124254-1f4fecb05e7c/go.mod h1:/6/9WzUMdFS1vpASkEoEleG7jM8/eHU3pRJc+w4kDhU= +github.com/saltbo/gopkg v0.0.0-20200814135303-dc29a68fb9c9 h1:K9VfDJXNQvZYlvucSafXU/nuYj9pMCZEk2MmMRFSc2c= +github.com/saltbo/gopkg v0.0.0-20200814135303-dc29a68fb9c9/go.mod h1:JbGH+WyetOnE2JBrCvKOZQ+D1c8+Jo/spErcqJxXyo8= +github.com/saltbo/gopkg v0.0.0-20200817013558-116ba552a859 h1:s1wklWFvNfJp5XESgF4FazxGmWuLiyqCeZUk6Enj1i4= +github.com/saltbo/gopkg v0.0.0-20200817013558-116ba552a859/go.mod h1:0gUfIXkMjNZSIrsbcbyUqSc9CausMiit0eSCnd1SgtA= github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= @@ -295,6 +346,7 @@ github.com/spf13/viper v1.7.1 h1:pM5oEahlgWv/WnHXpgbKz7iLIxRf65tye2Ci+XFK5sk= github.com/spf13/viper v1.7.1/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= @@ -302,14 +354,27 @@ github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= +github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14/go.mod h1:gxQT6pBGRuIGunNf/+tSOB5OHvguWi8Tbt82WOkf35E= +github.com/swaggo/gin-swagger v1.2.0 h1:YskZXEiv51fjOMTsXrOetAjrMDfFaXD79PEoQBOe2W0= +github.com/swaggo/gin-swagger v1.2.0/go.mod h1:qlH2+W7zXGZkczuL+r2nEBR2JTT+/lX05Nn6vPhc7OI= +github.com/swaggo/swag v1.5.1/go.mod h1:1Bl9F/ZBpVWh22nY0zmYyASPO1lI/zIwRDrpZU+tv8Y= +github.com/swaggo/swag v1.6.7 h1:e8GC2xDllJZr3omJkm9YfmK0Y56+rMO3cg0JBKNz09s= +github.com/swaggo/swag v1.6.7/go.mod h1:xDhTyuFIujYiN3DKWC/H/83xcfHp+UE/IzWWampG7Zc= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= +github.com/ugorji/go v1.1.5-pre/go.mod h1:FwP/aQVg39TXzItUBMwnWp9T9gPQnXw4Poh4/oBQZ/0= github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= +github.com/ugorji/go/codec v0.0.0-20181022190402-e5e69e061d4f/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= +github.com/ugorji/go/codec v1.1.5-pre/go.mod h1:tULtS6Gy1AE1yCENaw4Vb//HLH5njI2tfCQDUqRd8fI= github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs= github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= +github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= +github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= +github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= +github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/ziutek/mymysql v1.5.4 h1:GB0qdRGsTwQSBVYuVShFBKaXSnSnYYC2d9knnE1LHFs= github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= @@ -329,6 +394,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= @@ -350,10 +417,12 @@ golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181005035420-146acd28ed58/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -367,11 +436,15 @@ golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190611141213-3f473d35a33a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200513185701-a91f0712d120 h1:EZ3cVSzKOlJxAd8e8YAJ7no8nNypTxexh/YE/xW3ZEY= golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200707034311-ab3426394381 h1:VXak5I6aEWmAXeQjA+QSZzlgNrpq9mjcfDemuexIKsU= golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -382,6 +455,7 @@ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -390,13 +464,17 @@ golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181228144115-9a3f9b0469bb/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190610200419-93c9922d18ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -404,11 +482,15 @@ golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20u golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200805065543-0cf7623e9dbd h1:wefLe/3g5tC0FcXw3NneLA5tHgbyouyZlfcSjNfOdgk= golang.org/x/sys v0.0.0-20200805065543-0cf7623e9dbd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200808120158-1030fc2bf1d9 h1:yi1hN8dcqI9l8klZfy4B8mJvFmmAxJEePIQQFNSd7Cs= +golang.org/x/sys v0.0.0-20200808120158-1030fc2bf1d9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 h1:SvFZT6jyqRaOeXpc5h/JSfZenJ2O330aBsf7JfSUXmQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -424,7 +506,10 @@ golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3 golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190606050223-4d9ae51c2468/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190611222205-d73e1c7e250b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190614205625-5aca471b1d59/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= @@ -433,7 +518,11 @@ golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200809012840-6f4f008689da h1:ml5G98G4/tdKT1XNq+ky5iSRdKKux0TANlLAzmXT/hg= +golang.org/x/tools v0.0.0-20200809012840-6f4f008689da/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk= @@ -482,6 +571,8 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= +gopkg.in/go-playground/validator.v8 v8.18.2/go.mod h1:RX2a/7Ha8BgOhfk7j780h4/u/RRjR0eouCJSH80/M2Y= gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno= gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= diff --git a/model/matter.go b/model/matter.go index 7e2c485..d09c444 100644 --- a/model/matter.go +++ b/model/matter.go @@ -6,14 +6,18 @@ import ( type Matter struct { Id int64 `json:"id"` - Uid int64 `json:"uid" xorm:"notnull"` - Name string `json:"name" xorm:"notnull"` - Type string `json:"type" xorm:"notnull"` - Size int64 `json:"size" xorm:"notnull"` - Object string `json:"object" xorm:"notnull default ''"` - Dirtype int8 `json:"dirtype" xorm:"tinyint(1) notnull"` - Parent string `json:"parent" xorm:"notnull"` - Deleted time.Time `json:"deleted" xorm:"notnull deleted"` - Created time.Time `json:"created" xorm:"notnull created"` - Updated time.Time `json:"updated" xorm:"notnull updated"` + Uid int64 `json:"uid" gorm:"not null"` + Name string `json:"name" gorm:"not null"` + Type string `json:"type" gorm:"not null"` + Size int64 `json:"size" gorm:"not null"` + Object string `json:"object" gorm:"not null"` + Dirtype int8 `json:"dirtype" gorm:"not null"` + Parent string `json:"parent" gorm:"not null"` + Deleted time.Time `json:"deleted" gorm:"column:deleted_at;not null"` + Created time.Time `json:"created" gorm:"column:created_at;not null"` + Updated time.Time `json:"updated" gorm:"column:updated_at;not null"` +} + +func (Matter) TableName() string { + return "matter" } diff --git a/model/share.go b/model/share.go index 309fc4b..1e8ba61 100644 --- a/model/share.go +++ b/model/share.go @@ -6,15 +6,19 @@ import ( type Share struct { Id int64 `json:"id"` - Uid int64 `json:"uid" xorm:"notnull"` - Name string `json:"name" xorm:"notnull"` - Alias string `json:"alias" xorm:"varchar(16) notnull"` - Secret string `json:"secret" xorm:"varchar(16) notnull"` - MatterId int64 `json:"matter_id" xorm:"notnull"` - DownTimes int64 `json:"down_times" xorm:"notnull"` - ViewTimes int64 `json:"view_times" xorm:"notnull"` - ExpireAt time.Time `json:"expire_at" xorm:"notnull expire_at"` - Deleted time.Time `json:"deleted" xorm:"notnull deleted"` - Created time.Time `json:"created" xorm:"notnull created"` - Updated time.Time `json:"updated" xorm:"notnull updated"` + Uid int64 `json:"uid" gorm:"not null"` + Name string `json:"name" gorm:"not null"` + Alias string `json:"alias" gorm:"size:16;not null"` + Secret string `json:"secret" gorm:"size:16;not null"` + MatterId int64 `json:"matter_id" gorm:"not null"` + DownTimes int64 `json:"down_times" gorm:"not null"` + ViewTimes int64 `json:"view_times" gorm:"not null"` + ExpireAt time.Time `json:"expire_at" gorm:"column:expire_at;not null"` + Deleted time.Time `json:"deleted" gorm:"column:deleted_at;not null"` + Created time.Time `json:"created" gorm:"column:created_at;not null"` + Updated time.Time `json:"updated" gorm:"column:updated_at;not null"` +} + +func (Share) TableName() string { + return "share" } diff --git a/model/storage.go b/model/storage.go new file mode 100644 index 0000000..fbdb535 --- /dev/null +++ b/model/storage.go @@ -0,0 +1,19 @@ +package model + +import ( + "time" +) + +type Storage struct { + Id int64 `json:"id"` + UserId int64 `json:"user_id" gorm:"not null"` + Max uint64 `json:"max" gorm:"not null"` + Used uint64 `json:"used" gorm:"not null"` + Deleted time.Time `json:"deleted" gorm:"column:deleted_at;not null"` + Created time.Time `json:"created" gorm:"column:created_at;not null"` + Updated time.Time `json:"updated" gorm:"column:updated_at;not null"` +} + +func (Storage) TableName() string { + return "storage" +} diff --git a/model/user.go b/model/user.go deleted file mode 100644 index a11ed6a..0000000 --- a/model/user.go +++ /dev/null @@ -1,21 +0,0 @@ -package model - -import ( - "time" -) - -type User struct { - Id int64 `json:"id"` - Email string `json:"email" xorm:"varchar(32) notnull"` - Password string `json:"password" xorm:"varchar(64) notnull"` - Nickname string `json:"nickname" xorm:"varchar(32) notnull"` - Avatar string `json:"avatar" xorm:"varchar(255) notnull"` - Roles string `json:"roles" xorm:"varchar(64) notnull"` - StorageMax uint64 `json:"storage_max" xorm:"notnull"` - StorageUsed uint64 `json:"storage_used" xorm:"notnull"` - ActiveToken string `json:"active_token" xorm:"varchar(64) notnull"` - RecoverToken string `json:"recover_token" xorm:"varchar(64) notnull"` - Deleted time.Time `json:"deleted" xorm:"notnull deleted"` - Created time.Time `json:"created" xorm:"notnull created"` - Updated time.Time `json:"updated" xorm:"notnull updated"` -} diff --git a/rest/file.go b/rest/file.go index 9ca0290..a90a002 100644 --- a/rest/file.go +++ b/rest/file.go @@ -5,11 +5,13 @@ import ( "strings" "github.com/gin-gonic/gin" + "github.com/jinzhu/gorm" + "github.com/saltbo/gopkg/gormutil" "github.com/saltbo/gopkg/ginutil" - "github.com/saltbo/zpan/dao" "github.com/saltbo/zpan/disk" + "github.com/saltbo/zpan/service" "github.com/saltbo/zpan/model" "github.com/saltbo/zpan/rest/bind" @@ -78,10 +80,10 @@ func (f *FileResource) findAll(c *gin.Context) { query += " and type like ?" params = append(params, p.Type+"%") } - fmt.Println(params) - sn := dao.DB.Where(query, params...).Limit(p.Limit, p.Offset) - total, err := sn.Desc("dirtype").Asc("id").FindAndCount(&list) - if err != nil { + + var total int64 + sn := gormutil.DB().Debug().Where(query, params...).Find(&list).Count(&total) + if err := sn.Order("dirtype desc, id asc").Limit(p.Limit).Offset(p.Offset).Error; err != nil { ginutil.JSONServerError(c, err) return } @@ -96,10 +98,11 @@ func (f *FileResource) findFolders(c *gin.Context) { return } + var total int64 list := make([]model.Matter, 0) query := "uid=? and dirtype=? and parent=?" - sn := dao.DB.Where(query, c.GetInt64("uid"), DIRTYPE_USER, p.Parent) - total, err := sn.Limit(p.Limit, p.Offset).FindAndCount(&list) + sn := gormutil.DB().Where(query, c.GetInt64("uid"), DIRTYPE_USER, p.Parent).Find(&list).Count(&total) + err := sn.Limit(p.Limit).Offset(p.Offset).Error if err != nil { ginutil.JSONServerError(c, err) return @@ -116,18 +119,18 @@ func (f *FileResource) createFolder(c *gin.Context) { } uid := c.GetInt64("uid") - if !dao.DirExist(uid, p.Dir) { + if !service.DirExist(uid, p.Dir) { ginutil.JSONBadRequest(c, fmt.Errorf("direction %s not exist", p.Dir)) return } - m := model.Matter{ + m := &model.Matter{ Uid: uid, Dirtype: DIRTYPE_USER, Name: p.Name, Parent: p.Dir, } - if _, err := dao.DB.Insert(m); err != nil { + if err := gormutil.DB().Create(m).Error; err != nil { ginutil.JSONServerError(c, err) return } @@ -142,50 +145,39 @@ func (f *FileResource) fileCallback(c *gin.Context) { return } - user := new(model.User) - if exist, err := dao.DB.Id(p.Uid).Get(user); err != nil { - ginutil.JSONServerError(c, err) - return - } else if !exist { - ginutil.JSONBadRequest(c, fmt.Errorf("user not exist")) + storage := new(model.Storage) + if gormutil.DB().First(storage, "user_id=?", p.Uid).RecordNotFound() { + ginutil.JSONBadRequest(c, fmt.Errorf("storage not exist")) return } - exist, err := dao.DB.Where("object=?", p.Object).Exist(&model.Matter{}) - if err != nil { - ginutil.JSONServerError(c, err) - return - } else if exist { - ginutil.JSONBadRequest(c, fmt.Errorf("object %s already exist.", p.Object)) + if !gormutil.DB().First(&model.Matter{}, "object=?", p.Object).RecordNotFound() { + ginutil.JSONBadRequest(c, fmt.Errorf("object %s already exist", p.Object)) return } - session := dao.DB.NewSession() - defer session.Close() + fc := func(tx *gorm.DB) error { + m := &model.Matter{ + Uid: p.Uid, + Name: p.Name, + Type: p.Type, + Size: p.Size, + Parent: p.Dir, + Object: p.Object, + } + if err := tx.Create(m).Error; err != nil { + return err + } - m := model.Matter{ - Uid: p.Uid, - Name: p.Name, - Type: p.Type, - Size: p.Size, - Parent: p.Dir, - Object: p.Object, - } - if _, err := session.Insert(m); err != nil { - _ = session.Rollback() - ginutil.JSONServerError(c, err) - return - } + // update the service todo add lock for concurrent + storageUsed := storage.Used + uint64(p.Size) + if err := tx.Model(storage).Update("used", storageUsed).Error; err != nil { + return err + } - // update the storage - user.StorageUsed += uint64(p.Size) - if _, err := session.ID(p.Uid).Cols("storage_used").Update(user); err != nil { - _ = session.Rollback() - ginutil.JSONBadRequest(c, err) - return + return nil } - - if err := session.Commit(); err != nil { + if err := gormutil.DB().Transaction(fc); err != nil { ginutil.JSONServerError(c, err) return } @@ -200,7 +192,7 @@ func (f *FileResource) fileOperation(c *gin.Context) { return } - file, err := dao.FileGet(c.GetInt64("uid"), p.Id) + file, err := service.FileGet(c.GetInt64("uid"), p.Id) if err != nil { ginutil.JSONBadRequest(c, err) return @@ -208,12 +200,12 @@ func (f *FileResource) fileOperation(c *gin.Context) { switch p.Action { case OPERATION_COPY: - err = dao.FileCopy(file, p.Dest) + err = service.FileCopy(file, p.Dest) case OPERATION_MOVE: - err = dao.FileMove(file.Id, p.Dest) + err = service.FileMove(file.Id, p.Dest) case OPERATION_RENAME: if file.Dirtype > 0 { - if err := dao.DirRename(file.Id, p.Dest); err != nil { + if err := service.DirRename(file.Id, p.Dest); err != nil { ginutil.JSONServerError(c, err) return } @@ -227,7 +219,7 @@ func (f *FileResource) fileOperation(c *gin.Context) { ginutil.JSONServerError(c, err) return } - err = dao.FileRename(file.Id, p.Dest) + err = service.FileRename(file.Id, p.Dest) default: err = fmt.Errorf("invalid operation") } @@ -244,13 +236,13 @@ func (f *FileResource) delete(c *gin.Context) { uid := c.GetInt64("uid") fileId := c.Param("id") - user := new(model.User) - if _, err := dao.DB.Id(uid).Get(user); err != nil { - ginutil.JSONBadRequest(c, err) + storage := new(model.Storage) + if gormutil.DB().First(storage, "user_id=?", uid).RecordNotFound() { + ginutil.JSONBadRequest(c, fmt.Errorf("storage not exist")) return } - file, err := dao.FileGet(uid, fileId) + file, err := service.FileGet(uid, fileId) if err != nil { ginutil.JSONBadRequest(c, err) return @@ -261,25 +253,22 @@ func (f *FileResource) delete(c *gin.Context) { return } - session := dao.DB.NewSession() - defer session.Close() + fc := func(tx *gorm.DB) error { + // delete for the list + if err := tx.Delete(file).Error; err != nil { + return err + } - // delete for the list - if _, err := session.ID(file.Id).Delete(file); err != nil { - _ = session.Rollback() - ginutil.JSONServerError(c, err) - return - } + // update the user service todo add lock for concurrent + storageUsed := storage.Used - uint64(file.Size) + if err := tx.Model(storage).Update("used", storageUsed).Error; err != nil { + return err + } - // update the user storage - user.StorageUsed -= uint64(file.Size) - if _, err := session.ID(file.Uid).Cols("storage_used").Update(user); err != nil { - _ = session.Rollback() - ginutil.JSONServerError(c, err) - return + return nil } - if err := session.Commit(); err != nil { + if err := gormutil.DB().Transaction(fc); err != nil { ginutil.JSONServerError(c, err) return } diff --git a/rest/share.go b/rest/share.go index 16db4f4..7b5648d 100644 --- a/rest/share.go +++ b/rest/share.go @@ -6,10 +6,9 @@ import ( "github.com/gin-gonic/gin" "github.com/saltbo/gopkg/ginutil" + "github.com/saltbo/gopkg/gormutil" "github.com/saltbo/gopkg/randutil" - "github.com/saltbo/zpan/dao" - "github.com/saltbo/zpan/model" "github.com/saltbo/zpan/rest/bind" ) @@ -33,10 +32,7 @@ func (rs *ShareResource) find(c *gin.Context) { secret := c.Query("secret") share := new(model.Share) - if exist, err := dao.DB.Where("alias=?", c.Param("alias")).Get(share); err != nil { - ginutil.JSONServerError(c, err) - return - } else if !exist { + if gormutil.DB().First(share, "alias=?", c.Param("alias")).RecordNotFound() { ginutil.JSONBadRequest(c, fmt.Errorf("share not found")) return } else if secret == "" && share.Secret != "" { @@ -51,10 +47,7 @@ func (rs *ShareResource) find(c *gin.Context) { } matter := new(model.Matter) - if exist, err := dao.DB.Id(share.MatterId).Get(matter); err != nil { - ginutil.JSONServerError(c, err) - return - } else if !exist { + if gormutil.DB().First(matter, "id=?", share.MatterId).RecordNotFound() { ginutil.JSONBadRequest(c, fmt.Errorf("matter not exist")) return } @@ -69,10 +62,10 @@ func (rs *ShareResource) findAll(c *gin.Context) { return } + var total int64 list := make([]model.Share, 0) - sn := dao.DB.Limit(p.Limit, p.Offset) - total, err := sn.FindAndCount(&list) - if err != nil { + sn := gormutil.DB().Count(&total) + if err := sn.Limit(p.Limit).Offset(p.Offset).Find(&list).Error; err != nil { ginutil.JSONBadRequest(c, err) return } @@ -88,10 +81,7 @@ func (rs *ShareResource) create(c *gin.Context) { } matter := new(model.Matter) - if exist, err := dao.DB.Id(p.MId).Get(matter); err != nil { - ginutil.JSONBadRequest(c, err) - return - } else if !exist { + if gormutil.DB().First(matter, "id=?", p.MId).RecordNotFound() { ginutil.JSONBadRequest(c, fmt.Errorf("matter not found")) return } @@ -106,7 +96,7 @@ func (rs *ShareResource) create(c *gin.Context) { if p.Private { m.Secret = randutil.RandString(5) } - if _, err := dao.DB.Insert(m); err != nil { + if err := gormutil.DB().Create(m).Error; err != nil { ginutil.JSONServerError(c, err) return } @@ -122,10 +112,7 @@ func (rs *ShareResource) update(c *gin.Context) { } share := new(model.Share) - if exist, err := dao.DB.Id(p.Id).Get(share); err != nil { - ginutil.JSONBadRequest(c, err) - return - } else if !exist { + if gormutil.DB().First(share, "id=?", p.Id).RecordNotFound() { ginutil.JSONBadRequest(c, fmt.Errorf("share not found")) return } @@ -134,7 +121,7 @@ func (rs *ShareResource) update(c *gin.Context) { share.Secret = randutil.RandString(5) } - if _, err := dao.DB.Id(share.Id).Update(share); err != nil { + if err := gormutil.DB().Update(share).Error; err != nil { ginutil.JSONServerError(c, err) return } @@ -146,14 +133,12 @@ func (rs *ShareResource) delete(c *gin.Context) { alias := c.Param("alias") share := new(model.Share) - if exist, err := dao.DB.Where("alias=?", alias).Get(share); err != nil { - ginutil.JSONBadRequest(c, err) + if gormutil.DB().First(share, "alias=?", alias).RecordNotFound() { + ginutil.JSONBadRequest(c, fmt.Errorf("share not exist")) return - } else if !exist { - ginutil.JSONBadRequest(c, fmt.Errorf("matter not found")) } - if _, err := dao.DB.Id(share.Id).Delete(share); err != nil { + if err := gormutil.DB().Delete(share, "id=?", share.Id).Error; err != nil { ginutil.JSONServerError(c, err) return } diff --git a/rest/url.go b/rest/url.go index 675336d..fe0de76 100644 --- a/rest/url.go +++ b/rest/url.go @@ -12,10 +12,9 @@ import ( uuid "github.com/satori/go.uuid" "github.com/saltbo/zpan/config" - "github.com/saltbo/zpan/dao" "github.com/saltbo/zpan/disk" - "github.com/saltbo/zpan/model" "github.com/saltbo/zpan/rest/bind" + "github.com/saltbo/zpan/service" ) type URLResource struct { @@ -54,15 +53,12 @@ func (rs *URLResource) uploadURL(c *gin.Context) { } uid := c.GetInt64("uid") - user := new(model.User) - if _, err := dao.DB.Id(uid).Get(user); err != nil { - ginutil.JSONServerError(c, err) + if err := service.StorageQuotaVerify(uid, p.Size); err != nil { + ginutil.JSONBadRequest(c, err) return - } else if user.StorageUsed+uint64(p.Size) >= user.StorageMax { - ginutil.JSONBadRequest(c, fmt.Errorf("storage not enough space")) } - if !dao.DirExist(uid, p.Dir) { + if !service.DirExist(uid, p.Dir) { ginutil.JSONBadRequest(c, fmt.Errorf("direction %s not exist.", p.Dir)) } @@ -94,7 +90,7 @@ func (rs *URLResource) downloadURL(c *gin.Context) { uid := c.GetInt64("uid") fileId := c.Param("id") - file, err := dao.FileGet(uid, fileId) + file, err := service.FileGet(uid, fileId) if err != nil { ginutil.JSONBadRequest(c, err) return diff --git a/rest/user.go b/rest/user.go index e8c7f9e..ce8eb23 100644 --- a/rest/user.go +++ b/rest/user.go @@ -3,51 +3,30 @@ package rest import ( "github.com/gin-gonic/gin" "github.com/saltbo/gopkg/ginutil" - - "github.com/saltbo/zpan/dao" + "github.com/saltbo/gopkg/gormutil" "github.com/saltbo/zpan/model" - "github.com/saltbo/zpan/rest/bind" ) -type UserResource struct { -} - -func NewUserResource() ginutil.Resource { - return &UserResource{} +type StorageResource struct { } -func (rs *UserResource) Register(router *gin.RouterGroup) { - router.GET("/users", rs.findAll) - router.GET("/users/:uid", rs.find) +func NewStorageResource() *StorageResource { + return &StorageResource{} } -func (rs *UserResource) findAll(c *gin.Context) { - p := new(bind.QueryUser) - if err := c.BindQuery(p); err != nil { - ginutil.JSONBadRequest(c, err) - return - } - - list := make([]model.User, 0) - total, err := dao.DB.Limit(p.Limit, p.Offset).FindAndCount(&list) - if err != nil { - ginutil.JSONBadRequest(c, err) - return - } - - ginutil.JSONList(c, list, total) +func (rs *StorageResource) Register(router *gin.RouterGroup) { + router.GET("/storage/:uid", rs.find) } -func (rs *UserResource) find(c *gin.Context) { +func (rs *StorageResource) find(c *gin.Context) { userId := c.Param("uid") - user := new(model.User) - if _, err := dao.DB.Id(userId).Get(user); err != nil { + storage := new(model.Storage) + if err := gormutil.DB().First(storage, "user_id=?", userId).Error; err != nil { ginutil.JSONBadRequest(c, err) return } - user.Password = "" - ginutil.JSONData(c, user) + ginutil.JSONData(c, storage) } diff --git a/service/matter.go b/service/matter.go new file mode 100644 index 0000000..60abb18 --- /dev/null +++ b/service/matter.go @@ -0,0 +1,82 @@ +package service + +import ( + "fmt" + "strings" + + "github.com/jinzhu/gorm" + "github.com/saltbo/gopkg/gormutil" + + "github.com/saltbo/zpan/model" +) + +func DirExist(uid int64, dir string) bool { + if dir == "" { + return true + } + + items := strings.Split(dir, "/") + name := items[len(items)-2] + parent := strings.TrimSuffix(dir, name+"/") + return !gormutil.DB().Where("uid=? and name=? and parent=?", uid, name, parent).First(&model.Matter{}).RecordNotFound() +} + +func FileGet(uid int64, fileId interface{}) (*model.Matter, error) { + m := new(model.Matter) + if gormutil.DB().First(m, "id=?", fileId).RecordNotFound() { + return nil, fmt.Errorf("file not exist") + } else if m.Uid != uid { + return nil, fmt.Errorf("file not belong to you") + } + + return m, nil +} + +func FileCopy(srcFile *model.Matter, dest string) error { + m := &model.Matter{ + Uid: srcFile.Uid, + Name: srcFile.Name, + Type: srcFile.Type, + Size: srcFile.Size, + Parent: dest, + Object: srcFile.Object, + } + return gormutil.DB().Create(m).Error +} + +func FileMove(id int64, dest string) error { + return gormutil.DB().Model(model.Matter{Id: id}).Update("parent", dest).Error +} + +func FileRename(id int64, name string) error { + return gormutil.DB().Model(model.Matter{Id: id}).Update("name", name).Error +} + +func DirRename(id int64, name string) error { + matter := new(model.Matter) + if gormutil.DB().First(matter, "id=?", id).RecordNotFound() { + return fmt.Errorf("matter not exist") + } + + oldParent := fmt.Sprintf("%s%s/", matter.Parent, matter.Name) + newParent := fmt.Sprintf("%s%s/", matter.Parent, name) + list := make([]model.Matter, 0) + gormutil.DB().Where("parent like '" + oldParent + "%'").Find(&list) + + fc := func(tx *gorm.DB) error { + for _, v := range list { + parent := strings.Replace(v.Parent, oldParent, newParent, 1) + if err := tx.Model(v).Update("parent", parent).Error; err != nil { + return err + } + } + + if err := tx.Model(matter).Update("name", name).Error; err != nil { + return err + } + + return nil + } + + return gormutil.DB().Transaction(fc) +} diff --git a/service/storage.go b/service/storage.go new file mode 100644 index 0000000..79cbea8 --- /dev/null +++ b/service/storage.go @@ -0,0 +1,20 @@ +package service + +import ( + "fmt" + + "github.com/saltbo/gopkg/gormutil" + + "github.com/saltbo/zpan/model" +) + +func StorageQuotaVerify(uid, addonSize int64) error { + storage := new(model.Storage) + if err := gormutil.DB().First(storage, "user_id=?", uid).Error; err != nil { + return err + } else if storage.Used+uint64(addonSize) >= storage.Max { + return fmt.Errorf("service not enough space") + } + + return nil +}