Skip to content

Commit

Permalink
refactor: replace the xorm by the gormutil
Browse files Browse the repository at this point in the history
  • Loading branch information
saltbo committed Aug 17, 2020
1 parent fa0ccd5 commit 165376a
Show file tree
Hide file tree
Showing 18 changed files with 359 additions and 328 deletions.
10 changes: 6 additions & 4 deletions .zpan.yaml
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
22 changes: 13 additions & 9 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 10 additions & 9 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
31 changes: 0 additions & 31 deletions dao/db.go

This file was deleted.

92 changes: 0 additions & 92 deletions dao/matter.go

This file was deleted.

5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 165376a

Please sign in to comment.