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

@ -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