* refactor: rename package

* fix: fix govet issues

* fix: misspellings
This commit is contained in:
Hexxa 2018-05-30 08:09:13 -05:00 committed by GitHub
parent 2cbe4209a9
commit ac05637658
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 41 additions and 42 deletions

View file

@ -53,7 +53,7 @@ func TestLogin(t *testing.T) {
ret := srv.login(testCase.AdminId, testCase.AdminPwd, res) ret := srv.login(testCase.AdminId, testCase.AdminPwd, res)
if ret != testCase.Result { 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)) // verify cookie (only token.adminid part))

View file

@ -211,7 +211,6 @@ func (srv *SrvShare) AddLocalFilesImp() interface{} {
for _, info := range infos { for _, info := range infos {
info.DownLimit = srv.Conf.DownLimit info.DownLimit = srv.Conf.DownLimit
info.State = fileidx.StateDone info.State = fileidx.StateDone
info.PathLocal = info.PathLocal
info.Id = srv.Encryptor.Encrypt([]byte(info.PathLocal)) info.Id = srv.Encryptor.Encrypt([]byte(info.PathLocal))
addRet := srv.Index.Add(info) addRet := srv.Index.Add(info)

View file

@ -416,7 +416,7 @@ func TestPublishId(t *testing.T) {
} }
if res.ShareId != mockPublicId { 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: case httputil.MsgRes:

View file

@ -12,8 +12,8 @@ import (
"github.com/ihexxa/quickshare/server/libs/encrypt" "github.com/ihexxa/quickshare/server/libs/encrypt"
"github.com/ihexxa/quickshare/server/libs/fileidx" "github.com/ihexxa/quickshare/server/libs/fileidx"
"github.com/ihexxa/quickshare/server/libs/fsutil" "github.com/ihexxa/quickshare/server/libs/fsutil"
httpUtil "github.com/ihexxa/quickshare/server/libs/httputil" "github.com/ihexxa/quickshare/server/libs/httputil"
worker "github.com/ihexxa/quickshare/server/libs/httpworker" "github.com/ihexxa/quickshare/server/libs/httpworker"
) )
const DefaultId = "0" const DefaultId = "0"
@ -30,7 +30,7 @@ type ShareInfo struct {
func (srv *SrvShare) StartUploadHandler(res http.ResponseWriter, req *http.Request) { func (srv *SrvShare) StartUploadHandler(res http.ResponseWriter, req *http.Request) {
if req.Method != http.MethodPost { if req.Method != http.MethodPost {
srv.Http.Fill(httpUtil.Err404, res) srv.Http.Fill(httputil.Err404, res)
return return
} }
@ -39,30 +39,30 @@ func (srv *SrvShare) StartUploadHandler(res http.ResponseWriter, req *http.Reque
loginPass := srv.Walls.PassLoginCheck(tokenStr, req) loginPass := srv.Walls.PassLoginCheck(tokenStr, req)
opPass := srv.Walls.PassOpLimit(GetRemoteIp(req.RemoteAddr), srv.Conf.OpIdUpload) opPass := srv.Walls.PassOpLimit(GetRemoteIp(req.RemoteAddr), srv.Conf.OpIdUpload)
if !ipPass || !loginPass || !opPass { if !ipPass || !loginPass || !opPass {
srv.Http.Fill(httpUtil.Err429, res) srv.Http.Fill(httputil.Err429, res)
return return
} }
ack := make(chan error, 1) ack := make(chan error, 1)
ok := srv.WorkerPool.Put(&worker.Task{ ok := srv.WorkerPool.Put(&httpworker.Task{
Ack: ack, Ack: ack,
Do: srv.Wrap(srv.StartUpload), Do: srv.Wrap(srv.StartUpload),
Res: res, Res: res,
Req: req, Req: req,
}) })
if !ok { 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) execErr := srv.WorkerPool.IsInTime(ack, time.Duration(srv.Conf.Timeout)*time.Millisecond)
if srv.Err.IsErr(execErr) { 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) { func (srv *SrvShare) UploadHandler(res http.ResponseWriter, req *http.Request) {
if req.Method != http.MethodPost { if req.Method != http.MethodPost {
srv.Http.Fill(httpUtil.Err404, res) srv.Http.Fill(httputil.Err404, res)
return return
} }
@ -71,36 +71,36 @@ func (srv *SrvShare) UploadHandler(res http.ResponseWriter, req *http.Request) {
loginPass := srv.Walls.PassLoginCheck(tokenStr, req) loginPass := srv.Walls.PassLoginCheck(tokenStr, req)
opPass := srv.Walls.PassOpLimit(GetRemoteIp(req.RemoteAddr), srv.Conf.OpIdUpload) opPass := srv.Walls.PassOpLimit(GetRemoteIp(req.RemoteAddr), srv.Conf.OpIdUpload)
if !ipPass || !loginPass || !opPass { if !ipPass || !loginPass || !opPass {
srv.Http.Fill(httpUtil.Err429, res) srv.Http.Fill(httputil.Err429, res)
return return
} }
multiFormErr := req.ParseMultipartForm(srv.Conf.ParseFormBufSize) multiFormErr := req.ParseMultipartForm(srv.Conf.ParseFormBufSize)
if srv.Err.IsErr(multiFormErr) { if srv.Err.IsErr(multiFormErr) {
srv.Http.Fill(httpUtil.Err400, res) srv.Http.Fill(httputil.Err400, res)
return return
} }
ack := make(chan error, 1) ack := make(chan error, 1)
ok := srv.WorkerPool.Put(&worker.Task{ ok := srv.WorkerPool.Put(&httpworker.Task{
Ack: ack, Ack: ack,
Do: srv.Wrap(srv.Upload), Do: srv.Wrap(srv.Upload),
Res: res, Res: res,
Req: req, Req: req,
}) })
if !ok { 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) execErr := srv.WorkerPool.IsInTime(ack, time.Duration(srv.Conf.Timeout)*time.Millisecond)
if srv.Err.IsErr(execErr) { 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) { func (srv *SrvShare) FinishUploadHandler(res http.ResponseWriter, req *http.Request) {
if req.Method != http.MethodPost { if req.Method != http.MethodPost {
srv.Http.Fill(httpUtil.Err404, res) srv.Http.Fill(httputil.Err404, res)
return return
} }
@ -109,24 +109,24 @@ func (srv *SrvShare) FinishUploadHandler(res http.ResponseWriter, req *http.Requ
loginPass := srv.Walls.PassLoginCheck(tokenStr, req) loginPass := srv.Walls.PassLoginCheck(tokenStr, req)
opPass := srv.Walls.PassOpLimit(GetRemoteIp(req.RemoteAddr), srv.Conf.OpIdUpload) opPass := srv.Walls.PassOpLimit(GetRemoteIp(req.RemoteAddr), srv.Conf.OpIdUpload)
if !ipPass || !loginPass || !opPass { if !ipPass || !loginPass || !opPass {
srv.Http.Fill(httpUtil.Err429, res) srv.Http.Fill(httputil.Err429, res)
return return
} }
ack := make(chan error, 1) ack := make(chan error, 1)
ok := srv.WorkerPool.Put(&worker.Task{ ok := srv.WorkerPool.Put(&httpworker.Task{
Ack: ack, Ack: ack,
Do: srv.Wrap(srv.FinishUpload), Do: srv.Wrap(srv.FinishUpload),
Res: res, Res: res,
Req: req, Req: req,
}) })
if !ok { 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) execErr := srv.WorkerPool.IsInTime(ack, time.Duration(srv.Conf.Timeout)*time.Millisecond)
if srv.Err.IsErr(execErr) { 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{} { func (srv *SrvShare) startUpload(fileName string) interface{} {
if !IsValidFileName(fileName) { if !IsValidFileName(fileName) {
return httpUtil.Err400 return httputil.Err400
} }
id := DefaultId id := DefaultId
@ -157,12 +157,12 @@ func (srv *SrvShare) startUpload(fileName string) interface{} {
case 0: case 0:
// go on // go on
case -1: case -1:
return httpUtil.Err412 return httputil.Err412
case 1: case 1:
return httpUtil.Err500 // TODO: use correct status code return httputil.Err500 // TODO: use correct status code
default: default:
srv.Index.Del(id) srv.Index.Del(id)
return httpUtil.Err500 return httputil.Err500
} }
fullPath := filepath.Join(srv.Conf.PathLocal, info.PathLocal) fullPath := filepath.Join(srv.Conf.PathLocal, info.PathLocal)
@ -170,10 +170,10 @@ func (srv *SrvShare) startUpload(fileName string) interface{} {
switch { switch {
case createFileErr == fsutil.ErrExists: case createFileErr == fsutil.ErrExists:
srv.Index.Del(id) srv.Index.Del(id)
return httpUtil.Err412 return httputil.Err412
case createFileErr == fsutil.ErrUnknown: case createFileErr == fsutil.ErrUnknown:
srv.Index.Del(id) srv.Index.Del(id)
return httpUtil.Err500 return httputil.Err500
default: default:
srv.Index.SetState(id, fileidx.StateUploading) srv.Index.SetState(id, fileidx.StateUploading)
return &ByteRange{ return &ByteRange{
@ -193,7 +193,7 @@ func (srv *SrvShare) Upload(res http.ResponseWriter, req *http.Request) interfac
if srv.Err.IsErr(startErr) || if srv.Err.IsErr(startErr) ||
srv.Err.IsErr(lengthErr) || srv.Err.IsErr(lengthErr) ||
srv.Err.IsErr(chunkErr) { srv.Err.IsErr(chunkErr) {
return httpUtil.Err400 return httputil.Err400
} }
return srv.upload(shareId, start, length, chunk) 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{} { func (srv *SrvShare) upload(shareId string, start int64, length int64, chunk io.Reader) interface{} {
if !srv.IsValidShareId(shareId) { if !srv.IsValidShareId(shareId) {
return httpUtil.Err400 return httputil.Err400
} }
fileInfo, found := srv.Index.Get(shareId) fileInfo, found := srv.Index.Get(shareId)
if !found { if !found {
return httpUtil.Err404 return httputil.Err404
} }
if !srv.IsValidStart(start, fileInfo.Uploaded) || !srv.IsValidLength(length) { if !srv.IsValidStart(start, fileInfo.Uploaded) || !srv.IsValidLength(length) {
return httpUtil.Err400 return httputil.Err400
} }
fullPath := filepath.Join(srv.Conf.PathLocal, fileInfo.PathLocal) fullPath := filepath.Join(srv.Conf.PathLocal, fileInfo.PathLocal)
if !srv.Fs.CopyChunkN(fullPath, chunk, start, length) { if !srv.Fs.CopyChunkN(fullPath, chunk, start, length) {
return httpUtil.Err500 return httputil.Err500
} }
if srv.Index.IncrUploaded(shareId, length) == 0 { if srv.Index.IncrUploaded(shareId, length) == 0 {
return httpUtil.Err404 return httputil.Err404
} }
return &ByteRange{ return &ByteRange{
@ -236,7 +236,7 @@ func (srv *SrvShare) FinishUpload(res http.ResponseWriter, req *http.Request) in
func (srv *SrvShare) finishUpload(shareId string) interface{} { func (srv *SrvShare) finishUpload(shareId string) interface{} {
if !srv.Index.SetState(shareId, fileidx.StateDone) { if !srv.Index.SetState(shareId, fileidx.StateDone) {
return httpUtil.Err404 return httputil.Err404
} }
return &ShareInfo{ return &ShareInfo{

View file

@ -150,7 +150,7 @@ func TestStartUpload(t *testing.T) {
} }
case httputil.MsgRes: case httputil.MsgRes:
if response != expectRes { 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: default:
t.Fatalf(fmt.Sprintf("startUpload: type not found: %T %T", testCase.Output.Response, httputil.Err400)) 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: case httputil.MsgRes:
expectRes := testCase.Output.Response.(httputil.MsgRes) expectRes := testCase.Output.Response.(httputil.MsgRes)
if res != expectRes { 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: case *ShareInfo:
info, found := testCase.Output.IndexMap[res.ShareId] info, found := testCase.Output.IndexMap[res.ShareId]

View file

@ -269,7 +269,7 @@ func TestCopyRange(t *testing.T) {
} }
} }
if res.StatusCode != tCase.Output.StatusCode { 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 { 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)
} }
} }
} }

View file

@ -33,7 +33,7 @@ func TestIpLimit(t *testing.T) {
walls := newAccessWalls(1000, ttl, cyc, limit) walls := newAccessWalls(1000, ttl, cyc, limit)
testIpLimit(t, walls, ip, 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) time.Sleep(time.Duration(cyc) * time.Second)
testIpLimit(t, walls, ip, limit) 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) { func testIpLimit(t *testing.T, walls Walls, ip string, limit int16) {
for i := int16(0); i < limit; i++ { for i := int16(0); i < limit; i++ {
if !walls.PassIpLimit(ip) { 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) { 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, op1, limit)
testOpLimit(t, walls, resourceId, op2, 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) time.Sleep(time.Duration(ttl) * time.Second)
testOpLimit(t, walls, resourceId, op1, limit) testOpLimit(t, walls, resourceId, op1, limit)
testOpLimit(t, walls, resourceId, op2, limit) testOpLimit(t, walls, resourceId, op2, limit)