From ac05637658d58616e6fcdb1f1da0566c9468d052 Mon Sep 17 00:00:00 2001 From: Hexxa Date: Wed, 30 May 2018 08:09:13 -0500 Subject: [PATCH] Dev (#6) * refactor: rename package * fix: fix govet issues * fix: misspellings --- server/apis/auth_test.go | 2 +- server/apis/file_info.go | 1 - server/apis/file_info_test.go | 2 +- server/apis/upload.go | 62 +++++++++++++------------- server/apis/upload_test.go | 4 +- server/libs/qtube/qtube_test.go | 4 +- server/libs/walls/access_walls_test.go | 8 ++-- 7 files changed, 41 insertions(+), 42 deletions(-) diff --git a/server/apis/auth_test.go b/server/apis/auth_test.go index 94c4c98..1a84f78 100644 --- a/server/apis/auth_test.go +++ b/server/apis/auth_test.go @@ -53,7 +53,7 @@ func TestLogin(t *testing.T) { ret := srv.login(testCase.AdminId, testCase.AdminPwd, res) if ret != testCase.Result { - t.Fatalf("login: reponse=%v testCase=%v", ret, testCase.Result) + t.Fatalf("login: response=%v testCase=%v", ret, testCase.Result) } // verify cookie (only token.adminid part)) diff --git a/server/apis/file_info.go b/server/apis/file_info.go index f9333ac..4a7df47 100644 --- a/server/apis/file_info.go +++ b/server/apis/file_info.go @@ -211,7 +211,6 @@ func (srv *SrvShare) AddLocalFilesImp() interface{} { for _, info := range infos { info.DownLimit = srv.Conf.DownLimit info.State = fileidx.StateDone - info.PathLocal = info.PathLocal info.Id = srv.Encryptor.Encrypt([]byte(info.PathLocal)) addRet := srv.Index.Add(info) diff --git a/server/apis/file_info_test.go b/server/apis/file_info_test.go index e07f0ad..b6bf1b5 100644 --- a/server/apis/file_info_test.go +++ b/server/apis/file_info_test.go @@ -416,7 +416,7 @@ func TestPublishId(t *testing.T) { } if res.ShareId != mockPublicId { - t.Fatalf("shadowId: mockId incorrect", res.ShareId, mockPublicId) + t.Fatalf("shadowId: mockId incorrect %v %v", res.ShareId, mockPublicId) } case httputil.MsgRes: diff --git a/server/apis/upload.go b/server/apis/upload.go index 6971a28..3878ce6 100644 --- a/server/apis/upload.go +++ b/server/apis/upload.go @@ -12,8 +12,8 @@ import ( "github.com/ihexxa/quickshare/server/libs/encrypt" "github.com/ihexxa/quickshare/server/libs/fileidx" "github.com/ihexxa/quickshare/server/libs/fsutil" - httpUtil "github.com/ihexxa/quickshare/server/libs/httputil" - worker "github.com/ihexxa/quickshare/server/libs/httpworker" + "github.com/ihexxa/quickshare/server/libs/httputil" + "github.com/ihexxa/quickshare/server/libs/httpworker" ) const DefaultId = "0" @@ -30,7 +30,7 @@ type ShareInfo struct { func (srv *SrvShare) StartUploadHandler(res http.ResponseWriter, req *http.Request) { if req.Method != http.MethodPost { - srv.Http.Fill(httpUtil.Err404, res) + srv.Http.Fill(httputil.Err404, res) return } @@ -39,30 +39,30 @@ func (srv *SrvShare) StartUploadHandler(res http.ResponseWriter, req *http.Reque loginPass := srv.Walls.PassLoginCheck(tokenStr, req) opPass := srv.Walls.PassOpLimit(GetRemoteIp(req.RemoteAddr), srv.Conf.OpIdUpload) if !ipPass || !loginPass || !opPass { - srv.Http.Fill(httpUtil.Err429, res) + srv.Http.Fill(httputil.Err429, res) return } ack := make(chan error, 1) - ok := srv.WorkerPool.Put(&worker.Task{ + ok := srv.WorkerPool.Put(&httpworker.Task{ Ack: ack, Do: srv.Wrap(srv.StartUpload), Res: res, Req: req, }) if !ok { - srv.Http.Fill(httpUtil.Err503, res) + srv.Http.Fill(httputil.Err503, res) } execErr := srv.WorkerPool.IsInTime(ack, time.Duration(srv.Conf.Timeout)*time.Millisecond) if srv.Err.IsErr(execErr) { - srv.Http.Fill(httpUtil.Err500, res) + srv.Http.Fill(httputil.Err500, res) } } func (srv *SrvShare) UploadHandler(res http.ResponseWriter, req *http.Request) { if req.Method != http.MethodPost { - srv.Http.Fill(httpUtil.Err404, res) + srv.Http.Fill(httputil.Err404, res) return } @@ -71,36 +71,36 @@ func (srv *SrvShare) UploadHandler(res http.ResponseWriter, req *http.Request) { loginPass := srv.Walls.PassLoginCheck(tokenStr, req) opPass := srv.Walls.PassOpLimit(GetRemoteIp(req.RemoteAddr), srv.Conf.OpIdUpload) if !ipPass || !loginPass || !opPass { - srv.Http.Fill(httpUtil.Err429, res) + srv.Http.Fill(httputil.Err429, res) return } multiFormErr := req.ParseMultipartForm(srv.Conf.ParseFormBufSize) if srv.Err.IsErr(multiFormErr) { - srv.Http.Fill(httpUtil.Err400, res) + srv.Http.Fill(httputil.Err400, res) return } ack := make(chan error, 1) - ok := srv.WorkerPool.Put(&worker.Task{ + ok := srv.WorkerPool.Put(&httpworker.Task{ Ack: ack, Do: srv.Wrap(srv.Upload), Res: res, Req: req, }) if !ok { - srv.Http.Fill(httpUtil.Err503, res) + srv.Http.Fill(httputil.Err503, res) } execErr := srv.WorkerPool.IsInTime(ack, time.Duration(srv.Conf.Timeout)*time.Millisecond) if srv.Err.IsErr(execErr) { - srv.Http.Fill(httpUtil.Err500, res) + srv.Http.Fill(httputil.Err500, res) } } func (srv *SrvShare) FinishUploadHandler(res http.ResponseWriter, req *http.Request) { if req.Method != http.MethodPost { - srv.Http.Fill(httpUtil.Err404, res) + srv.Http.Fill(httputil.Err404, res) return } @@ -109,24 +109,24 @@ func (srv *SrvShare) FinishUploadHandler(res http.ResponseWriter, req *http.Requ loginPass := srv.Walls.PassLoginCheck(tokenStr, req) opPass := srv.Walls.PassOpLimit(GetRemoteIp(req.RemoteAddr), srv.Conf.OpIdUpload) if !ipPass || !loginPass || !opPass { - srv.Http.Fill(httpUtil.Err429, res) + srv.Http.Fill(httputil.Err429, res) return } ack := make(chan error, 1) - ok := srv.WorkerPool.Put(&worker.Task{ + ok := srv.WorkerPool.Put(&httpworker.Task{ Ack: ack, Do: srv.Wrap(srv.FinishUpload), Res: res, Req: req, }) if !ok { - srv.Http.Fill(httpUtil.Err503, res) + srv.Http.Fill(httputil.Err503, res) } execErr := srv.WorkerPool.IsInTime(ack, time.Duration(srv.Conf.Timeout)*time.Millisecond) if srv.Err.IsErr(execErr) { - srv.Http.Fill(httpUtil.Err500, res) + srv.Http.Fill(httputil.Err500, res) } } @@ -136,7 +136,7 @@ func (srv *SrvShare) StartUpload(res http.ResponseWriter, req *http.Request) int func (srv *SrvShare) startUpload(fileName string) interface{} { if !IsValidFileName(fileName) { - return httpUtil.Err400 + return httputil.Err400 } id := DefaultId @@ -157,12 +157,12 @@ func (srv *SrvShare) startUpload(fileName string) interface{} { case 0: // go on case -1: - return httpUtil.Err412 + return httputil.Err412 case 1: - return httpUtil.Err500 // TODO: use correct status code + return httputil.Err500 // TODO: use correct status code default: srv.Index.Del(id) - return httpUtil.Err500 + return httputil.Err500 } fullPath := filepath.Join(srv.Conf.PathLocal, info.PathLocal) @@ -170,10 +170,10 @@ func (srv *SrvShare) startUpload(fileName string) interface{} { switch { case createFileErr == fsutil.ErrExists: srv.Index.Del(id) - return httpUtil.Err412 + return httputil.Err412 case createFileErr == fsutil.ErrUnknown: srv.Index.Del(id) - return httpUtil.Err500 + return httputil.Err500 default: srv.Index.SetState(id, fileidx.StateUploading) return &ByteRange{ @@ -193,7 +193,7 @@ func (srv *SrvShare) Upload(res http.ResponseWriter, req *http.Request) interfac if srv.Err.IsErr(startErr) || srv.Err.IsErr(lengthErr) || srv.Err.IsErr(chunkErr) { - return httpUtil.Err400 + return httputil.Err400 } return srv.upload(shareId, start, length, chunk) @@ -201,25 +201,25 @@ func (srv *SrvShare) Upload(res http.ResponseWriter, req *http.Request) interfac func (srv *SrvShare) upload(shareId string, start int64, length int64, chunk io.Reader) interface{} { if !srv.IsValidShareId(shareId) { - return httpUtil.Err400 + return httputil.Err400 } fileInfo, found := srv.Index.Get(shareId) if !found { - return httpUtil.Err404 + return httputil.Err404 } if !srv.IsValidStart(start, fileInfo.Uploaded) || !srv.IsValidLength(length) { - return httpUtil.Err400 + return httputil.Err400 } fullPath := filepath.Join(srv.Conf.PathLocal, fileInfo.PathLocal) if !srv.Fs.CopyChunkN(fullPath, chunk, start, length) { - return httpUtil.Err500 + return httputil.Err500 } if srv.Index.IncrUploaded(shareId, length) == 0 { - return httpUtil.Err404 + return httputil.Err404 } return &ByteRange{ @@ -236,7 +236,7 @@ func (srv *SrvShare) FinishUpload(res http.ResponseWriter, req *http.Request) in func (srv *SrvShare) finishUpload(shareId string) interface{} { if !srv.Index.SetState(shareId, fileidx.StateDone) { - return httpUtil.Err404 + return httputil.Err404 } return &ShareInfo{ diff --git a/server/apis/upload_test.go b/server/apis/upload_test.go index 75e75df..2338439 100644 --- a/server/apis/upload_test.go +++ b/server/apis/upload_test.go @@ -150,7 +150,7 @@ func TestStartUpload(t *testing.T) { } case httputil.MsgRes: if response != expectRes { - t.Fatalf(fmt.Sprintf("startUpload: reponse=%v expectRes=%v", response, expectRes)) + t.Fatalf(fmt.Sprintf("startUpload: response=%v expectRes=%v", response, expectRes)) } default: t.Fatalf(fmt.Sprintf("startUpload: type not found: %T %T", testCase.Output.Response, httputil.Err400)) @@ -353,7 +353,7 @@ func TestFinishUpload(t *testing.T) { case httputil.MsgRes: expectRes := testCase.Output.Response.(httputil.MsgRes) if res != expectRes { - t.Fatalf(fmt.Sprintf("finishUpload: reponse=%v expectRes=%v", res, expectRes)) + t.Fatalf(fmt.Sprintf("finishUpload: response=%v expectRes=%v", res, expectRes)) } case *ShareInfo: info, found := testCase.Output.IndexMap[res.ShareId] diff --git a/server/libs/qtube/qtube_test.go b/server/libs/qtube/qtube_test.go index d150680..e980e8e 100644 --- a/server/libs/qtube/qtube_test.go +++ b/server/libs/qtube/qtube_test.go @@ -269,7 +269,7 @@ func TestCopyRange(t *testing.T) { } } if res.StatusCode != tCase.Output.StatusCode { - t.Fatalf("copyRange: statusCodes are not match %v", res.StatusCode, tCase.Output.StatusCode) + t.Fatalf("copyRange: statusCodes are not match got: %v want: %v", res.StatusCode, tCase.Output.StatusCode) } } } @@ -348,7 +348,7 @@ func TestServeAll(t *testing.T) { } } if res.StatusCode != tCase.Output.StatusCode { - t.Fatalf("serveAll: statusCodes are not match %v", res.StatusCode, tCase.Output.StatusCode) + t.Fatalf("serveAll: statusCodes are not match got: %v want: %v", res.StatusCode, tCase.Output.StatusCode) } } } diff --git a/server/libs/walls/access_walls_test.go b/server/libs/walls/access_walls_test.go index d8a4eb8..d75a6c2 100644 --- a/server/libs/walls/access_walls_test.go +++ b/server/libs/walls/access_walls_test.go @@ -33,7 +33,7 @@ func TestIpLimit(t *testing.T) { walls := newAccessWalls(1000, ttl, cyc, limit) testIpLimit(t, walls, ip, limit) - // wait for tokens are re-fullfilled + // wait for tokens are re-fulfilled time.Sleep(time.Duration(cyc) * time.Second) testIpLimit(t, walls, ip, limit) @@ -43,12 +43,12 @@ func TestIpLimit(t *testing.T) { func testIpLimit(t *testing.T, walls Walls, ip string, limit int16) { for i := int16(0); i < limit; i++ { if !walls.PassIpLimit(ip) { - t.Fatalf("ipLimiter: should be passed", time.Now().Unix()) + t.Fatalf("ipLimiter: should be passed %d", time.Now().Unix()) } } if walls.PassIpLimit(ip) { - t.Fatalf("ipLimiter: should not be passed", time.Now().Unix()) + t.Fatalf("ipLimiter: should not be passed %d", time.Now().Unix()) } } @@ -62,7 +62,7 @@ func TestOpLimit(t *testing.T) { testOpLimit(t, walls, resourceId, op1, limit) testOpLimit(t, walls, resourceId, op2, limit) - // wait for tokens are re-fullfilled + // wait for tokens are re-fulfilled time.Sleep(time.Duration(ttl) * time.Second) testOpLimit(t, walls, resourceId, op1, limit) testOpLimit(t, walls, resourceId, op2, limit)