Refine the structure of this project.

This commit is contained in:
zicla
2019-04-26 14:32:15 +08:00
parent e88930e13a
commit c251ed9f1b
69 changed files with 5494 additions and 2251 deletions

View File

@ -1,10 +1,10 @@
package config
import (
"github.com/eyebluecn/tank/code/logger"
"github.com/eyebluecn/tank/code/tool/util"
"github.com/json-iterator/go"
"io/ioutil"
"tank/code/logger"
"tank/code/tool/util"
"time"
"unsafe"
)
@ -13,7 +13,6 @@ const (
//用户身份的cookie字段名
COOKIE_AUTH_KEY = "_ak"
//数据库表前缀 tank200表示当前应用版本是tank:2.0.x版数据库结构发生变化必然是中型升级
TABLE_PREFIX = "tank20_"

View File

@ -2,11 +2,11 @@ package logger
import (
"fmt"
"github.com/eyebluecn/tank/code/tool/util"
"log"
"os"
"runtime"
"sync"
"tank/code/tool/util"
"time"
)

View File

@ -2,12 +2,12 @@ package main
import (
"fmt"
"github.com/eyebluecn/tank/code/config"
"github.com/eyebluecn/tank/code/logger"
"github.com/eyebluecn/tank/code/rest"
_ "github.com/go-sql-driver/mysql"
"log"
"net/http"
"tank/code/config"
"tank/code/logger"
"tank/code/rest"
)
func main() {

View File

@ -2,11 +2,11 @@ package rest
import (
"fmt"
"github.com/eyebluecn/tank/code/tool/result"
"github.com/eyebluecn/tank/code/tool/util"
"net/http"
"regexp"
"strconv"
"tank/code/tool/result"
"tank/code/tool/util"
"time"
)

View File

@ -2,9 +2,9 @@ package rest
import (
"fmt"
"github.com/eyebluecn/tank/code/tool/result"
"github.com/eyebluecn/tank/code/tool/util"
"net/http"
"tank/code/tool/result"
"tank/code/tool/util"
"time"
)

View File

@ -2,10 +2,10 @@ package rest
import (
"fmt"
"github.com/eyebluecn/tank/code/tool/result"
"github.com/json-iterator/go"
"go/types"
"net/http"
"tank/code/tool/result"
)
type IController interface {

View File

@ -1,6 +1,6 @@
package rest
import "tank/code/tool/builder"
import "github.com/eyebluecn/tank/code/tool/builder"
type BaseDao struct {
Bean

View File

@ -1,14 +1,14 @@
package rest
import (
"github.com/eyebluecn/tank/code/config"
"math"
"reflect"
"tank/code/config"
"time"
)
const (
TRUE = "true"
TRUE = "true"
FALSE = "false"
)

View File

@ -1,11 +1,11 @@
package rest
import (
"github.com/eyebluecn/tank/code/config"
"github.com/eyebluecn/tank/code/logger"
"github.com/eyebluecn/tank/code/tool/result"
"github.com/eyebluecn/tank/code/tool/util"
"net/http"
"tank/code/config"
"tank/code/logger"
"tank/code/tool/result"
"tank/code/tool/util"
)
type IBean interface {
@ -38,15 +38,12 @@ func (this *Bean) Cleanup() {
//处理错误的统一方法 可以省去if err!=nil 这段代码
func (this *Bean) PanicError(err error) {
if err != nil {
panic(err)
}
util.PanicError(err)
}
//能找到一个user就找到一个
func (this *Bean) findUser(writer http.ResponseWriter, request *http.Request) *User {
//验证用户是否已经登录。
//登录身份有效期以数据库中记录的为准
sessionId := util.GetSessionUuidFromRequest(request, config.COOKIE_AUTH_KEY)

View File

@ -2,11 +2,11 @@ package rest
import (
"fmt"
"github.com/eyebluecn/tank/code/config"
"github.com/eyebluecn/tank/code/logger"
cache2 "github.com/eyebluecn/tank/code/tool/cache"
"github.com/jinzhu/gorm"
"reflect"
"tank/code/config"
"tank/code/logger"
cache2 "tank/code/tool/cache"
)
//全局唯一的上下文(在main函数中初始化)
@ -178,7 +178,6 @@ func (this *Context) initBeans() {
}
}
//系统如果安装好了就调用这个方法。
func (this *Context) InstallOk() {

View File

@ -1,10 +1,10 @@
package rest
import (
"github.com/eyebluecn/tank/code/tool/builder"
"github.com/eyebluecn/tank/code/tool/result"
"net/http"
"strconv"
"tank/code/tool/builder"
"tank/code/tool/result"
)
type DashboardController struct {
@ -75,20 +75,20 @@ func (this *DashboardController) Page(writer http.ResponseWriter, request *http.
sortArray := []builder.OrderPair{
{
key: "create_time",
value: orderCreateTime,
Key: "create_time",
Value: orderCreateTime,
},
{
key: "update_time",
value: orderUpdateTime,
Key: "update_time",
Value: orderUpdateTime,
},
{
key: "sort",
value: orderSort,
Key: "sort",
Value: orderSort,
},
{
key: "dt",
value: orderDt,
Key: "dt",
Value: orderDt,
},
}
@ -97,7 +97,6 @@ func (this *DashboardController) Page(writer http.ResponseWriter, request *http.
return this.Success(pager)
}
func (this *DashboardController) ActiveIpTop10(writer http.ResponseWriter, request *http.Request) *result.WebResult {
list := this.dashboardDao.ActiveIpTop10()
return this.Success(list)

View File

@ -1,9 +1,9 @@
package rest
import (
"github.com/eyebluecn/tank/code/tool/builder"
"github.com/jinzhu/gorm"
"github.com/nu7hatch/gouuid"
"tank/code/tool/builder"
"time"
)
@ -85,8 +85,8 @@ func (this *DashboardDao) ActiveIpTop10() []*DashboardIpTimes {
sortArray := []builder.OrderPair{
{
key: "times",
value: "DESC",
Key: "times",
Value: "DESC",
},
}
rows, err := CONTEXT.DB.Model(&Footprint{}).

View File

@ -1,6 +1,6 @@
package rest
import "tank/code/config"
import "github.com/eyebluecn/tank/code/config"
/**
* 系统的所有访问记录均记录在此

View File

@ -1,7 +1,7 @@
package rest
import (
"tank/code/tool/util"
"github.com/eyebluecn/tank/code/tool/util"
"time"
)

View File

@ -3,12 +3,12 @@ package rest
import (
"bytes"
"fmt"
"github.com/eyebluecn/tank/code/tool/result"
"github.com/eyebluecn/tank/code/tool/util"
"io/ioutil"
"net/http"
"regexp"
"strings"
"tank/code/tool/result"
"tank/code/tool/util"
)
/**

View File

@ -2,11 +2,11 @@ package rest
import (
"fmt"
"github.com/eyebluecn/tank/code/tool/dav"
"github.com/eyebluecn/tank/code/tool/dav/xml"
"net/http"
"path"
"strconv"
"tank/code/tool/dav"
"tank/code/tool/dav/xml"
)
//访问前缀,这个是特殊入口

View File

@ -2,15 +2,15 @@ package rest
import (
"fmt"
"github.com/eyebluecn/tank/code/tool/dav"
"github.com/eyebluecn/tank/code/tool/dav/xml"
"github.com/eyebluecn/tank/code/tool/result"
"github.com/eyebluecn/tank/code/tool/util"
"net/http"
"net/url"
"path"
"regexp"
"strings"
dav2 "tank/code/tool/dav"
xml2 "tank/code/tool/dav/xml"
"tank/code/tool/result"
"tank/code/tool/util"
)
/**
@ -63,18 +63,18 @@ func (this *DavService) ParseDepth(request *http.Request) int {
return depth
}
func (this *DavService) makePropstatResponse(href string, pstats []dav2.Propstat) *dav2.Response {
resp := dav2.Response{
func (this *DavService) makePropstatResponse(href string, pstats []dav.Propstat) *dav.Response {
resp := dav.Response{
Href: []string{(&url.URL{Path: href}).EscapedPath()},
Propstat: make([]dav2.SubPropstat, 0, len(pstats)),
Propstat: make([]dav.SubPropstat, 0, len(pstats)),
}
for _, p := range pstats {
var xmlErr *dav2.XmlError
var xmlErr *dav.XmlError
if p.XMLError != "" {
xmlErr = &dav2.XmlError{InnerXML: []byte(p.XMLError)}
xmlErr = &dav.XmlError{InnerXML: []byte(p.XMLError)}
}
resp.Propstat = append(resp.Propstat, dav2.SubPropstat{
Status: fmt.Sprintf("HTTP/1.1 %d %s", p.Status, dav2.StatusText(p.Status)),
resp.Propstat = append(resp.Propstat, dav.SubPropstat{
Status: fmt.Sprintf("HTTP/1.1 %d %s", p.Status, dav.StatusText(p.Status)),
Prop: p.Props,
ResponseDescription: p.ResponseDescription,
Error: xmlErr,
@ -84,11 +84,11 @@ func (this *DavService) makePropstatResponse(href string, pstats []dav2.Propstat
}
//从一个matter中获取其 []dav.Propstat
func (this *DavService) PropstatsFromXmlNames(user *User, matter *Matter, xmlNames []xml2.Name) []dav2.Propstat {
func (this *DavService) PropstatsFromXmlNames(user *User, matter *Matter, xmlNames []xml.Name) []dav.Propstat {
propstats := make([]dav2.Propstat, 0)
propstats := make([]dav.Propstat, 0)
var properties []dav2.Property
var properties []dav.Property
for _, xmlName := range xmlNames {
//TODO: deadprops尚未考虑
@ -97,7 +97,7 @@ func (this *DavService) PropstatsFromXmlNames(user *User, matter *Matter, xmlNam
if liveProp := LivePropMap[xmlName]; liveProp.findFn != nil && (liveProp.dir || !matter.Dir) {
innerXML := liveProp.findFn(user, matter)
properties = append(properties, dav2.Property{
properties = append(properties, dav.Property{
XMLName: xmlName,
InnerXML: []byte(innerXML),
})
@ -110,7 +110,7 @@ func (this *DavService) PropstatsFromXmlNames(user *User, matter *Matter, xmlNam
panic(result.BadRequest("请求的属性项无法解析!"))
}
okPropstat := dav2.Propstat{Status: http.StatusOK, Props: properties}
okPropstat := dav.Propstat{Status: http.StatusOK, Props: properties}
propstats = append(propstats, okPropstat)
@ -119,9 +119,9 @@ func (this *DavService) PropstatsFromXmlNames(user *User, matter *Matter, xmlNam
}
//从一个matter中获取所有的propsNames
func (this *DavService) AllPropXmlNames(matter *Matter) []xml2.Name {
func (this *DavService) AllPropXmlNames(matter *Matter) []xml.Name {
pnames := make([]xml2.Name, 0)
pnames := make([]xml.Name, 0)
for pn, prop := range LivePropMap {
if prop.findFn != nil && (prop.dir || !matter.Dir) {
pnames = append(pnames, pn)
@ -132,9 +132,9 @@ func (this *DavService) AllPropXmlNames(matter *Matter) []xml2.Name {
}
//从一个matter中获取其 []dav.Propstat
func (this *DavService) Propstats(user *User, matter *Matter, propfind *dav2.Propfind) []dav2.Propstat {
func (this *DavService) Propstats(user *User, matter *Matter, propfind *dav.Propfind) []dav.Propstat {
propstats := make([]dav2.Propstat, 0)
propstats := make([]dav.Propstat, 0)
if propfind.Propname != nil {
panic(result.BadRequest("propfind.Propname != nil 尚未处理"))
} else if propfind.Allprop != nil {
@ -161,7 +161,7 @@ func (this *DavService) HandlePropfind(writer http.ResponseWriter, request *http
depth := this.ParseDepth(request)
//读取请求参数。按照用户的参数请求返回内容。
propfind := dav2.ReadPropfind(request.Body)
propfind := dav.ReadPropfind(request.Body)
//寻找符合条件的matter.
//如果是空或者/就是请求根目录
@ -179,7 +179,7 @@ func (this *DavService) HandlePropfind(writer http.ResponseWriter, request *http
}
//准备一个输出结果的Writer
multiStatusWriter := &dav2.MultiStatusWriter{Writer: writer}
multiStatusWriter := &dav.MultiStatusWriter{Writer: writer}
for _, matter := range matters {

View File

@ -1,7 +1,6 @@
package rest
import (
"github.com/nu7hatch/gouuid"
"time"
)

View File

@ -1,7 +1,7 @@
package rest
import (
"tank/code/config"
"github.com/eyebluecn/tank/code/config"
"time"
)

View File

@ -1,10 +1,10 @@
package rest
import (
"github.com/eyebluecn/tank/code/tool/builder"
"github.com/eyebluecn/tank/code/tool/result"
"net/http"
"strconv"
"tank/code/tool/builder"
"tank/code/tool/result"
)
type FootprintController struct {
@ -95,12 +95,12 @@ func (this *FootprintController) Page(writer http.ResponseWriter, request *http.
sortArray := []builder.OrderPair{
{
key: "create_time",
value: orderCreateTime,
Key: "create_time",
Value: orderCreateTime,
},
{
key: "size",
value: orderSize,
Key: "size",
Value: orderSize,
},
}

View File

@ -1,8 +1,8 @@
package rest
import (
"github.com/eyebluecn/tank/code/tool/builder"
"github.com/jinzhu/gorm"
"tank/code/tool/builder"
"github.com/nu7hatch/gouuid"
"time"
@ -119,7 +119,6 @@ func (this *FootprintDao) AvgCostBetweenTime(startTime time.Time, endTime time.T
return int64(cost)
}
//执行清理操作
func (this *FootprintDao) Cleanup() {
this.logger.Info("[FootprintDao]执行清理清除数据库中所有Footprint记录。")

View File

@ -1,6 +1,6 @@
package rest
import "tank/code/config"
import "github.com/eyebluecn/tank/code/config"
/**
* 系统的所有访问记录均记录在此

View File

@ -2,9 +2,9 @@ package rest
import (
"encoding/json"
"github.com/eyebluecn/tank/code/config"
"github.com/eyebluecn/tank/code/tool/util"
"net/http"
"tank/code/config"
"tank/code/tool/util"
"time"
)

View File

@ -1,11 +1,11 @@
package rest
import (
"github.com/eyebluecn/tank/code/tool/builder"
"github.com/eyebluecn/tank/code/tool/result"
"net/http"
"strconv"
"strings"
"tank/code/tool/builder"
"tank/code/tool/result"
)
type ImageCacheController struct {
@ -100,21 +100,21 @@ func (this *ImageCacheController) Page(writer http.ResponseWriter, request *http
sortArray := []builder.OrderPair{
{
key: "create_time",
value: orderCreateTime,
Key: "create_time",
Value: orderCreateTime,
},
{
key: "update_time",
value: orderUpdateTime,
Key: "update_time",
Value: orderUpdateTime,
},
{
key: "sort",
value: orderSort,
Key: "sort",
Value: orderSort,
},
{
key: "size",
value: orderSize,
Key: "size",
Value: orderSize,
},
}

View File

@ -2,12 +2,12 @@ package rest
import (
"fmt"
"github.com/eyebluecn/tank/code/tool/builder"
"github.com/eyebluecn/tank/code/tool/util"
"github.com/jinzhu/gorm"
"github.com/nu7hatch/gouuid"
"os"
"path/filepath"
"tank/code/tool/builder"
"tank/code/tool/util"
"time"
)
@ -200,11 +200,9 @@ func (this *ImageCacheDao) SizeBetweenTime(startTime time.Time, endTime time.Tim
return size
}
//执行清理操作
func (this *ImageCacheDao) Cleanup() {
this.logger.Info("[ImageCacheDao]执行清理清除数据库中所有ImageCache记录。")
db := CONTEXT.DB.Where("uuid is not null").Delete(ImageCache{})
this.PanicError(db.Error)
}

View File

@ -1,7 +1,7 @@
package rest
import (
"tank/code/config"
"github.com/eyebluecn/tank/code/config"
)
/**

View File

@ -3,13 +3,13 @@ package rest
import (
"fmt"
"github.com/disintegration/imaging"
"github.com/eyebluecn/tank/code/tool/util"
"image"
"net/http"
"os"
"path/filepath"
"strconv"
"strings"
"tank/code/tool/util"
)
//@Service

View File

@ -2,6 +2,10 @@ package rest
import (
"fmt"
"github.com/eyebluecn/tank/code/config"
"github.com/eyebluecn/tank/code/tool/builder"
"github.com/eyebluecn/tank/code/tool/result"
"github.com/eyebluecn/tank/code/tool/util"
"github.com/jinzhu/gorm"
"github.com/json-iterator/go"
"github.com/nu7hatch/gouuid"
@ -11,10 +15,6 @@ import (
"os"
"regexp"
"strconv"
"tank/code/config"
"tank/code/tool/builder"
"tank/code/tool/result"
"tank/code/tool/util"
"time"
)

View File

@ -1,11 +1,11 @@
package rest
import (
"github.com/eyebluecn/tank/code/tool/builder"
"github.com/eyebluecn/tank/code/tool/result"
"net/http"
"strconv"
"strings"
"tank/code/tool/builder"
"tank/code/tool/result"
)
type MatterController struct {
@ -137,32 +137,32 @@ func (this *MatterController) Page(writer http.ResponseWriter, request *http.Req
sortArray := []builder.OrderPair{
{
key: "dir",
value: orderDir,
Key: "dir",
Value: orderDir,
},
{
key: "create_time",
value: orderCreateTime,
Key: "create_time",
Value: orderCreateTime,
},
{
key: "update_time",
value: orderUpdateTime,
Key: "update_time",
Value: orderUpdateTime,
},
{
key: "sort",
value: orderSort,
Key: "sort",
Value: orderSort,
},
{
key: "size",
value: orderSize,
Key: "size",
Value: orderSize,
},
{
key: "name",
value: orderName,
Key: "name",
Value: orderName,
},
{
key: "times",
value: orderTimes,
Key: "times",
Value: orderTimes,
},
}

View File

@ -1,13 +1,13 @@
package rest
import (
"github.com/eyebluecn/tank/code/config"
"github.com/eyebluecn/tank/code/tool/builder"
"github.com/eyebluecn/tank/code/tool/result"
"github.com/eyebluecn/tank/code/tool/util"
"github.com/jinzhu/gorm"
"github.com/nu7hatch/gouuid"
"os"
"tank/code/config"
"tank/code/tool/builder"
"tank/code/tool/result"
"tank/code/tool/util"
"time"
)

View File

@ -2,20 +2,19 @@ package rest
import (
"fmt"
"tank/code/config"
"tank/code/tool/util"
"github.com/eyebluecn/tank/code/config"
"github.com/eyebluecn/tank/code/tool/util"
)
const (
//根目录的uuid
MATTER_ROOT = "root"
MATTER_ROOT = "root"
//cache文件夹名称
MATTER_CACHE = "cache"
//matter名称最大长度
MATTER_NAME_MAX_LENGTH = 200
//matter文件夹最大深度
MATTER_NAME_MAX_DEPTH = 32
)
/**
@ -51,7 +50,6 @@ func (this *Matter) MimeType() string {
return util.GetMimeType(util.GetExtension(this.Name))
}
//创建一个 ROOT 的matter主要用于统一化处理移动复制等内容。
func NewRootMatter(user *User) *Matter {
matter := &Matter{}
@ -81,4 +79,3 @@ func GetUserCacheRootDir(username string) (rootDirPath string) {
return rootDirPath
}

View File

@ -1,14 +1,14 @@
package rest
import (
"github.com/eyebluecn/tank/code/tool/download"
"github.com/eyebluecn/tank/code/tool/result"
"github.com/eyebluecn/tank/code/tool/util"
"io"
"net/http"
"os"
"regexp"
"strings"
download2 "tank/code/tool/download"
"tank/code/tool/result"
"tank/code/tool/util"
)
/**
@ -65,7 +65,7 @@ func (this *MatterService) DownloadFile(
filename string,
withContentDisposition bool) {
download2.DownloadFile(writer, request, filePath, filename, withContentDisposition)
download.DownloadFile(writer, request, filePath, filename, withContentDisposition)
}
//删除文件

View File

@ -1,9 +1,9 @@
package rest
import (
"github.com/eyebluecn/tank/code/tool/result"
"github.com/eyebluecn/tank/code/tool/util"
"net/http"
"tank/code/tool/result"
"tank/code/tool/util"
)
type PreferenceController struct {

View File

@ -1,8 +1,8 @@
package rest
import (
"github.com/eyebluecn/tank/code/tool/result"
"github.com/nu7hatch/gouuid"
"tank/code/tool/result"
"time"
)
@ -55,7 +55,6 @@ func (this *PreferenceDao) Save(preference *Preference) *Preference {
return preference
}
//执行清理操作
func (this *PreferenceDao) Cleanup() {

View File

@ -1,6 +1,6 @@
package rest
import "tank/code/config"
import "github.com/eyebluecn/tank/code/config"
type Preference struct {
Base

View File

@ -2,15 +2,15 @@ package rest
import (
"fmt"
"github.com/eyebluecn/tank/code/config"
"github.com/eyebluecn/tank/code/logger"
"github.com/eyebluecn/tank/code/tool/result"
"github.com/eyebluecn/tank/code/tool/util"
"github.com/json-iterator/go"
"io"
"net/http"
"os"
"strings"
"tank/code/config"
"tank/code/logger"
"tank/code/tool/result"
"tank/code/tool/util"
"time"
)

View File

@ -1,7 +1,6 @@
package rest
import (
"github.com/nu7hatch/gouuid"
"time"
)
@ -46,7 +45,6 @@ func (this *SessionDao) Create(session *Session) *Session {
return session
}
//修改一个session
func (this *SessionDao) Save(session *Session) *Session {
@ -57,7 +55,6 @@ func (this *SessionDao) Save(session *Session) *Session {
return session
}
func (this *SessionDao) Delete(uuid string) {
session := this.CheckByUuid(uuid)
@ -69,7 +66,6 @@ func (this *SessionDao) Delete(uuid string) {
}
//执行清理操作
func (this *SessionDao) Cleanup() {
this.logger.Info("[SessionDao]执行清理清除数据库中所有Session记录。")

View File

@ -1,15 +1,15 @@
package rest
import (
"tank/code/config"
"github.com/eyebluecn/tank/code/config"
"time"
)
type Session struct {
Base
UserUuid string `json:"userUuid" gorm:"type:char(36)"`
Ip string `json:"ip" gorm:"type:varchar(128) not null"`
ExpireTime time.Time `json:"expireTime" gorm:"type:timestamp not null;default:'2018-01-01 00:00:00'"`
UserUuid string `json:"userUuid" gorm:"type:char(36)"`
Ip string `json:"ip" gorm:"type:varchar(128) not null"`
ExpireTime time.Time `json:"expireTime" gorm:"type:timestamp not null;default:'2018-01-01 00:00:00'"`
}
// set User's table name to be `profiles`

View File

@ -1,7 +1,6 @@
package rest
import (
"github.com/nu7hatch/gouuid"
"time"
)

View File

@ -1,7 +1,7 @@
package rest
import (
"tank/code/config"
"github.com/eyebluecn/tank/code/config"
"time"
)

View File

@ -1,13 +1,13 @@
package rest
import (
"github.com/eyebluecn/tank/code/config"
"github.com/eyebluecn/tank/code/tool/builder"
"github.com/eyebluecn/tank/code/tool/result"
"github.com/eyebluecn/tank/code/tool/util"
"net/http"
"regexp"
"strconv"
"tank/code/config"
"tank/code/tool/builder"
"tank/code/tool/result"
"tank/code/tool/util"
"time"
)
@ -279,20 +279,20 @@ func (this *UserController) Page(writer http.ResponseWriter, request *http.Reque
sortArray := []builder.OrderPair{
{
key: "create_time",
value: orderCreateTime,
Key: "create_time",
Value: orderCreateTime,
},
{
key: "update_time",
value: orderUpdateTime,
Key: "update_time",
Value: orderUpdateTime,
},
{
key: "sort",
value: orderSort,
Key: "sort",
Value: orderSort,
},
{
key: "last_time",
value: orderLastTime,
Key: "last_time",
Value: orderLastTime,
},
}

View File

@ -1,8 +1,8 @@
package rest
import (
"github.com/eyebluecn/tank/code/tool/builder"
"github.com/nu7hatch/gouuid"
"tank/code/tool/builder"
"time"
)

View File

@ -1,7 +1,7 @@
package rest
import (
"tank/code/config"
"github.com/eyebluecn/tank/code/config"
"time"
)
@ -22,7 +22,7 @@ const (
const (
//正常状态
USER_STATUS_OK = "OK"
USER_STATUS_OK = "OK"
//被禁用
USER_STATUS_DISABLED = "DISABLED"
)

View File

@ -1,10 +1,10 @@
package rest
import (
"github.com/eyebluecn/tank/code/config"
"github.com/eyebluecn/tank/code/tool/cache"
"github.com/eyebluecn/tank/code/tool/result"
"net/http"
"tank/code/config"
cache2 "tank/code/tool/cache"
"tank/code/tool/result"
"time"
)
@ -15,7 +15,7 @@ type UserService struct {
sessionDao *SessionDao
//操作文件的锁。
locker *cache2.Table
locker *cache.Table
}
//初始化方法
@ -34,10 +34,9 @@ func (this *UserService) Init() {
}
//创建一个用于存储用户文件锁的缓存。
this.locker = cache2.NewTable()
this.locker = cache.NewTable()
}
//对某个用户进行加锁。加锁阶段用户是不允许操作文件的。
func (this *UserService) MatterLock(userUuid string) {
//如果已经是锁住的状态,直接报错
@ -58,7 +57,6 @@ func (this *UserService) MatterLock(userUuid string) {
this.locker.Add(userUuid, duration, true)
}
//对某个用户解锁,解锁后用户可以操作文件。
func (this *UserService) MatterUnlock(userUuid string) {
@ -71,7 +69,6 @@ func (this *UserService) MatterUnlock(userUuid string) {
}
}
//装载session信息如果session没有了根据cookie去装填用户信息。
//在所有的路由最初会调用这个方法
func (this *UserService) bootstrap(writer http.ResponseWriter, request *http.Request) {

View File

@ -2,15 +2,15 @@ package test
import (
"bytes"
dav2 "tank/code/tool/dav"
xml2 "tank/code/tool/dav/xml"
"github.com/eyebluecn/tank/code/tool/dav"
"github.com/eyebluecn/tank/code/tool/dav/xml"
"testing"
"time"
)
func TestXmlDecoder(t *testing.T) {
propfind := &dav2.Propfind{}
propfind := &dav.Propfind{}
str := `
<?xml version="1.0" encoding="utf-8" ?>
@ -26,7 +26,7 @@ func TestXmlDecoder(t *testing.T) {
reader := bytes.NewReader([]byte(str))
err := xml2.NewDecoder(reader).Decode(propfind)
err := xml.NewDecoder(reader).Decode(propfind)
if err != nil {
t.Error(err.Error())
}
@ -58,18 +58,18 @@ func TestXmlEncoder(t *testing.T) {
writer := &bytes.Buffer{}
response := &dav2.Response{
XMLName: xml2.Name{Space: "DAV:", Local: "response"},
response := &dav.Response{
XMLName: xml.Name{Space: "DAV:", Local: "response"},
Href: []string{"/api/dav"},
Propstat: []dav2.SubPropstat{
Propstat: []dav.SubPropstat{
{
Prop: []dav2.Property{
Prop: []dav.Property{
{
XMLName: xml2.Name{Space: "DAV:", Local: "resourcetype"},
XMLName: xml.Name{Space: "DAV:", Local: "resourcetype"},
InnerXML: []byte(`<D:collection xmlns:D="DAV:"/>`),
},
{
XMLName: xml2.Name{Space: "DAV:", Local: "getlastmodified"},
XMLName: xml.Name{Space: "DAV:", Local: "getlastmodified"},
InnerXML: []byte(`Mon, 22 Apr 2019 06:38:36 GMT`),
},
},
@ -78,7 +78,7 @@ func TestXmlEncoder(t *testing.T) {
},
}
err := xml2.NewEncoder(writer).Encode(response)
err := xml.NewEncoder(writer).Encode(response)
if err != nil {
t.Error(err.Error())

View File

@ -6,7 +6,6 @@ import (
"testing"
)
func TestHello(t *testing.T) {
split := strings.Split("good", "/")

View File

@ -27,4 +27,3 @@ func (this *WherePair) Or(where *WherePair) *WherePair {
}
}

View File

@ -3,9 +3,9 @@ package cache
import (
"errors"
"fmt"
"github.com/eyebluecn/tank/code/tool/util"
"sort"
"sync"
"tank/code/tool/util"
"time"
)
@ -385,7 +385,6 @@ func (table *Table) MostAccessed(count int64) []*Item {
return r
}
// 打印日志
func (table *Table) log(format string, v ...interface{}) {
//TODO: 全局日志记录

View File

@ -8,10 +8,10 @@ import (
"bytes"
"errors"
"fmt"
"github.com/eyebluecn/tank/code/tool/dav/xml"
"github.com/eyebluecn/tank/code/tool/result"
"io"
"net/http"
"tank/code/tool/dav/xml"
"tank/code/tool/result"
)
// Proppatch describes a property update instruction as defined in RFC 4918.
@ -47,7 +47,6 @@ type Propstat struct {
ResponseDescription string
}
// DeadPropsHolder holds the dead properties of a resource.
//
// Dead properties are those properties that are explicitly defined. In
@ -77,7 +76,6 @@ type DeadPropsHolder interface {
Patch([]Proppatch) ([]Propstat, error)
}
func EscapeXML(s string) string {
for i := 0; i < len(s); i++ {
// As an optimization, if s contains only ASCII letters, digits or a
@ -98,8 +96,6 @@ func EscapeXML(s string) string {
return s
}
// http://www.webdav.org/specs/rfc4918.html#status.code.extensions.to.http11
const (
StatusMulti = 207
@ -125,14 +121,11 @@ func StatusText(code int) string {
return http.StatusText(code)
}
var (
errInvalidPropfind = errors.New("webdav: invalid propfind")
errInvalidResponse = errors.New("webdav: invalid response")
errInvalidPropfind = errors.New("webdav: invalid propfind")
errInvalidResponse = errors.New("webdav: invalid response")
)
// http://www.webdav.org/specs/rfc4918.html#ELEMENT_lockinfo
type LockInfo struct {
XMLName xml.Name `xml:"lockinfo"`
@ -147,7 +140,6 @@ type Owner struct {
InnerXML string `xml:",innerxml"`
}
//这是一个带字节计数器的Reader可以知道总共读取了多少个字节。
type CountingReader struct {
n int
@ -160,7 +152,6 @@ func (c *CountingReader) Read(p []byte) (int, error) {
return n, err
}
// Next returns the next token, if any, in the XML stream of d.
// RFC 4918 requires to ignore comments, processing instructions
// and directives.
@ -242,7 +233,7 @@ func ReadPropfind(reader io.Reader) (propfind *Propfind) {
panic(result.BadRequest(err.Error()))
}
if propfind.Allprop == nil && propfind.Include != nil {
if propfind.Allprop == nil && propfind.Include != nil {
panic(result.BadRequest(errInvalidPropfind.Error()))
}
if propfind.Allprop != nil && (propfind.Prop != nil || propfind.Propname != nil) {

View File

@ -3,6 +3,8 @@ package download
import (
"errors"
"fmt"
"github.com/eyebluecn/tank/code/tool/result"
"github.com/eyebluecn/tank/code/tool/util"
"io"
"mime/multipart"
"net/http"
@ -11,8 +13,6 @@ import (
"os"
"strconv"
"strings"
"tank/code/tool/result"
"tank/code/tool/util"
"time"
)

View File

@ -1,8 +1,7 @@
package util
//带有panic恢复的方法
func PanicHandler() {
func PanicHandler() {
if err := recover(); err != nil {
//TODO 全局日志记录
//LOGGER.Error("异步任务错误: %v", err)
@ -10,11 +9,15 @@ func PanicHandler() {
}
//带有panic恢复的方法
func SafeMethod(f func()) {
func SafeMethod(f func()) {
defer PanicHandler()
//执行函数
f()
}
//处理错误的统一方法 可以省去if err!=nil 这段代码
func PanicError(err error) {
if err != nil {
panic(err)
}
}

View File

@ -2,6 +2,7 @@ package util
import (
"fmt"
"github.com/eyebluecn/tank/code/tool/result"
"go/build"
"io"
"io/ioutil"
@ -9,7 +10,6 @@ import (
"os/user"
"path/filepath"
"strings"
"tank/code/tool/result"
)
//判断文件或文件夹是否已经存在
@ -43,14 +43,14 @@ func GetHomePath() string {
//如果exPath中包含了 /private/var/folders 我们认为是在Mac的开发环境中
macDev := strings.HasPrefix(exPath, "/private/var/folders")
if macDev {
exPath = GetGoPath() + "/src/tank/tmp"
exPath = GetGoPath() + "/src/github.com/eyebluecn/tank/tmp"
}
//如果exPath中包含了 \\AppData\\Local\\Temp 我们认为是在Win的开发环境中
systemUser, err := user.Current()
winDev := strings.HasPrefix(exPath, systemUser.HomeDir+"\\AppData\\Local\\Temp")
if winDev {
exPath = GetGoPath() + "/src/tank/tmp"
exPath = GetGoPath() + "/src/github.com/eyebluecn/tank/tmp"
}
return exPath