core: Move packages into pkg/ and internal/ folders

This commit is contained in:
Marius 2019-06-11 18:23:20 +02:00
parent 6f5b74b875
commit 42bfe35457
55 changed files with 199 additions and 240 deletions

View File

@ -2,27 +2,6 @@
set -e
# Find all packages containing Go source code inside the current directory
packages=$(find ./ -maxdepth 2 -name '*.go' -printf '%h\n' | sort | uniq)
# Some packages only support Go1.10+ and therefore we will only run the
# corresponding tests on these versions.
goversion=$(go version)
if [[ "$goversion" == *"go1.5"* ]] ||
[[ "$goversion" == *"go1.6"* ]] ||
[[ "$goversion" == *"go1.7"* ]] ||
[[ "$goversion" == *"go1.8"* ]] ||
[[ "$goversion" == *"go1.9"* ]]; then
echo "Skipping tests requiring GCSStore, which is not supported on $goversion"
packages=$(echo "$packages" | sed '/gcsstore/d')
echo "Skipping tests requiring Prometheus, which is not supported on $goversion"
packages=$(echo "$packages" | sed '/prometheuscollector/d')
else
go get -u github.com/prometheus/client_golang/prometheus
fi
install_etcd_pkgs() {
ETCD_VERSION="3.3.10"
go get -u go.etcd.io/etcd/clientv3
@ -32,26 +11,14 @@ install_etcd_pkgs() {
export PATH="$PATH:/tmp/etcd-v$ETCD_VERSION-linux-amd64"
}
# The etcd 3.3.x package only supports Go1.11+ and therefore
# we will only run the corresponding tests on these versions.
if [[ "$goversion" == *"go1.5"* ]] ||
[[ "$goversion" == *"go1.6"* ]] ||
[[ "$goversion" == *"go1.7"* ]] ||
[[ "$goversion" == *"go1.8"* ]] ||
[[ "$goversion" == *"go1.9"* ]] ||
[[ "$goversion" == *"go1.10"* ]]; then
echo "Skipping tests requiring etcd3locker, which is not supported on $goversion"
packages=$(echo "$packages" | sed '/etcd3locker/d')
else
# Install the etcd packages which are not vendored.
install_etcd_pkgs
fi
# Install the AWS SDK which is explicitly not vendored
go get -u github.com/aws/aws-sdk-go/service/s3
go get -u github.com/aws/aws-sdk-go/aws/...
# Test all packages which are allowed on all Go versions
go test $packages
go get -u github.com/prometheus/client_golang/prometheus
go vet $packages
# Install the etcd packages which are not vendored.
install_etcd_pkgs
go test ./pkg/...
go vet ./pkg/...

View File

@ -3,23 +3,23 @@ package cli
import (
"os"
"github.com/tus/tusd"
"github.com/tus/tusd/filestore"
"github.com/tus/tusd/gcsstore"
"github.com/tus/tusd/memorylocker"
"github.com/tus/tusd/s3store"
"github.com/tus/tusd/pkg/filestore"
"github.com/tus/tusd/pkg/gcsstore"
"github.com/tus/tusd/pkg/handler"
"github.com/tus/tusd/pkg/memorylocker"
"github.com/tus/tusd/pkg/s3store"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
)
var Composer *tusd.StoreComposer
var Composer *handler.StoreComposer
func CreateComposer() {
// Attempt to use S3 as a backend if the -s3-bucket option has been supplied.
// If not, we default to storing them locally on disk.
Composer = tusd.NewStoreComposer()
Composer = handler.NewStoreComposer()
if Flags.S3Bucket != "" {
s3Config := aws.NewConfig()

View File

@ -4,17 +4,17 @@ import (
"fmt"
"strconv"
"github.com/tus/tusd"
"github.com/tus/tusd/cmd/tusd/cli/hooks"
"github.com/tus/tusd/pkg/handler"
)
var hookHandler hooks.HookHandler = nil
type hookDataStore struct {
tusd.DataStore
handler.DataStore
}
func (store hookDataStore) NewUpload(info tusd.FileInfo) (id string, err error) {
func (store hookDataStore) NewUpload(info handler.FileInfo) (id string, err error) {
if output, err := invokeHookSync(hooks.HookPreCreate, info, true); err != nil {
if hookErr, ok := err.(hooks.HookError); ok {
return "", hooks.NewHookError(
@ -36,7 +36,7 @@ func SetupHookMetrics() {
MetricsHookErrorsTotal.WithLabelValues(string(hooks.HookPreCreate)).Add(0)
}
func SetupPreHooks(composer *tusd.StoreComposer) error {
func SetupPreHooks(composer *handler.StoreComposer) error {
if Flags.FileHooksDir != "" {
hookHandler = &hooks.FileHook{
Directory: Flags.FileHooksDir,
@ -66,7 +66,7 @@ func SetupPreHooks(composer *tusd.StoreComposer) error {
return nil
}
func SetupPostHooks(handler *tusd.Handler) {
func SetupPostHooks(handler *handler.Handler) {
go func() {
for {
select {
@ -83,14 +83,14 @@ func SetupPostHooks(handler *tusd.Handler) {
}()
}
func invokeHookAsync(typ hooks.HookType, info tusd.FileInfo) {
func invokeHookAsync(typ hooks.HookType, info handler.FileInfo) {
go func() {
// Error handling is taken care by the function.
_, _ = invokeHookSync(typ, info, false)
}()
}
func invokeHookSync(typ hooks.HookType, info tusd.FileInfo, captureOutput bool) ([]byte, error) {
func invokeHookSync(typ hooks.HookType, info handler.FileInfo, captureOutput bool) ([]byte, error) {
switch typ {
case hooks.HookPostFinish:
logEv(stdout, "UploadFinished", "id", info.ID, "size", strconv.FormatInt(info.Size, 10))

View File

@ -7,7 +7,7 @@ import (
"os/exec"
"strconv"
"github.com/tus/tusd"
"github.com/tus/tusd/pkg/handler"
)
type FileHook struct {
@ -18,7 +18,7 @@ func (_ FileHook) Setup() error {
return nil
}
func (h FileHook) InvokeHook(typ HookType, info tusd.FileInfo, captureOutput bool) ([]byte, int, error) {
func (h FileHook) InvokeHook(typ HookType, info handler.FileInfo, captureOutput bool) ([]byte, int, error) {
hookPath := h.Directory + string(os.PathSeparator) + string(typ)
cmd := exec.Command(hookPath)
env := os.Environ()

View File

@ -1,12 +1,12 @@
package hooks
import (
"github.com/tus/tusd"
"github.com/tus/tusd/pkg/handler"
)
type HookHandler interface {
Setup() error
InvokeHook(typ HookType, info tusd.FileInfo, captureOutput bool) ([]byte, int, error)
InvokeHook(typ HookType, info handler.FileInfo, captureOutput bool) ([]byte, int, error)
}
type HookType string
@ -20,7 +20,7 @@ const (
)
type hookDataStore struct {
tusd.DataStore
handler.DataStore
}
type HookError struct {

View File

@ -8,7 +8,7 @@ import (
"net/http"
"time"
"github.com/tus/tusd"
"github.com/tus/tusd/pkg/handler"
"github.com/sethgrid/pester"
)
@ -23,7 +23,7 @@ func (_ HttpHook) Setup() error {
return nil
}
func (h HttpHook) InvokeHook(typ HookType, info tusd.FileInfo, captureOutput bool) ([]byte, int, error) {
func (h HttpHook) InvokeHook(typ HookType, info handler.FileInfo, captureOutput bool) ([]byte, int, error) {
jsonInfo, err := json.Marshal(info)
if err != nil {
return nil, 0, err

View File

@ -4,15 +4,15 @@ import (
"fmt"
"plugin"
"github.com/tus/tusd"
"github.com/tus/tusd/pkg/handler"
)
type PluginHookHandler interface {
PreCreate(info tusd.FileInfo) error
PostCreate(info tusd.FileInfo) error
PostReceive(info tusd.FileInfo) error
PostFinish(info tusd.FileInfo) error
PostTerminate(info tusd.FileInfo) error
PreCreate(info handler.FileInfo) error
PostCreate(info handler.FileInfo) error
PostReceive(info handler.FileInfo) error
PostFinish(info handler.FileInfo) error
PostTerminate(info handler.FileInfo) error
}
type PluginHook struct {
@ -41,7 +41,7 @@ func (h *PluginHook) Setup() error {
return nil
}
func (h PluginHook) InvokeHook(typ HookType, info tusd.FileInfo, captureOutput bool) ([]byte, int, error) {
func (h PluginHook) InvokeHook(typ HookType, info handler.FileInfo, captureOutput bool) ([]byte, int, error) {
var err error
switch typ {
case HookPostFinish:

View File

@ -4,12 +4,12 @@ import (
"log"
"os"
"github.com/tus/tusd"
"github.com/tus/tusd/pkg/handler"
)
var stdout = log.New(os.Stdout, "[tusd] ", log.Ldate|log.Ltime)
var stderr = log.New(os.Stderr, "[tusd] ", log.Ldate|log.Ltime)
func logEv(logOutput *log.Logger, eventName string, details ...string) {
tusd.LogEvent(logOutput, eventName, details...)
handler.LogEvent(logOutput, eventName, details...)
}

View File

@ -3,8 +3,8 @@ package cli
import (
"net/http"
"github.com/tus/tusd"
"github.com/tus/tusd/prometheuscollector"
"github.com/tus/tusd/pkg/handler"
"github.com/tus/tusd/pkg/prometheuscollector"
"github.com/prometheus/client_golang/prometheus"
)
@ -22,7 +22,7 @@ var MetricsHookErrorsTotal = prometheus.NewCounterVec(
[]string{"hooktype"},
)
func SetupMetrics(handler *tusd.Handler) {
func SetupMetrics(handler *handler.Handler) {
prometheus.MustRegister(MetricsOpenConnections)
prometheus.MustRegister(MetricsHookErrorsTotal)
prometheus.MustRegister(prometheuscollector.New(handler.Metrics))

View File

@ -5,7 +5,7 @@ import (
"net/http"
"time"
"github.com/tus/tusd"
"github.com/tus/tusd/pkg/handler"
)
// Setups the different components, starts a Listener and give it to
@ -19,7 +19,7 @@ func Serve() {
stderr.Fatalf("Unable to setup hooks for handler: %s", err)
}
handler, err := tusd.NewHandler(tusd.Config{
handler, err := handler.NewHandler(handler.Config{
MaxSize: Flags.MaxSize,
BasePath: Flags.Basepath,
RespectForwardedHeaders: Flags.BehindProxy,

View File

@ -1,23 +0,0 @@
package tusd_test
import (
"github.com/tus/tusd"
"github.com/tus/tusd/filestore"
"github.com/tus/tusd/memorylocker"
)
func ExampleNewStoreComposer() {
composer := tusd.NewStoreComposer()
fs := filestore.New("./data")
fs.UseIn(composer)
ml := memorylocker.New()
ml.UseIn(composer)
config := tusd.Config{
StoreComposer: composer,
}
_, _ = tusd.NewHandler(config)
}

View File

@ -6,7 +6,7 @@ import (
"context"
"time"
"github.com/tus/tusd"
"github.com/tus/tusd/pkg/handler"
"go.etcd.io/etcd/clientv3/concurrency"
)
@ -32,7 +32,7 @@ func (lock *etcd3Lock) Acquire() error {
// the lock is most likely already taken
if err := lock.Mutex.Lock(ctx); err != nil {
if err == context.DeadlineExceeded {
return tusd.ErrFileLocked
return handler.ErrFileLocked
} else {
return err
}

View File

@ -17,7 +17,7 @@
//
// The locker will need to be included in composer that is used by tusd:
//
// composer := tusd.NewStoreComposer()
// composer := handler.NewStoreComposer()
// locker.UseIn(composer)
//
// For a shared etcd3 cluster, you may want to modify the prefix that etcd3locker uses:
@ -47,7 +47,7 @@ import (
"sync"
"time"
"github.com/tus/tusd"
"github.com/tus/tusd/pkg/handler"
etcd3 "go.etcd.io/etcd/clientv3"
"go.etcd.io/etcd/clientv3/concurrency"
)
@ -89,7 +89,7 @@ func NewWithLockerOptions(client *etcd3.Client, opts LockerOptions) (*Etcd3Locke
}
// UseIn adds this locker to the passed composer.
func (locker *Etcd3Locker) UseIn(composer *tusd.StoreComposer) {
func (locker *Etcd3Locker) UseIn(composer *handler.StoreComposer) {
composer.UseLocker(locker)
}

View File

@ -8,7 +8,7 @@ import (
"time"
"github.com/stretchr/testify/assert"
"github.com/tus/tusd"
"github.com/tus/tusd/pkg/handler"
)
func TestEtcd3Locker(t *testing.T) {
@ -40,11 +40,11 @@ func TestEtcd3Locker(t *testing.T) {
locker, err := NewWithLockerOptions(client, lockerOptions)
a.NoError(err)
a.NoError(locker.LockUpload("one"))
a.Equal(tusd.ErrFileLocked, locker.LockUpload("one"))
a.Equal(handler.ErrFileLocked, locker.LockUpload("one"))
time.Sleep(5 * time.Second)
// test that we can't take over the upload via a different etcd3 session
// while an upload is already taking place; testing etcd3 session KeepAlive
a.Equal(tusd.ErrFileLocked, locker.LockUpload("one"))
a.Equal(handler.ErrFileLocked, locker.LockUpload("one"))
a.NoError(locker.UnlockUpload("one"))
a.Equal(ErrLockNotHeld, locker.UnlockUpload("one"))
@ -52,8 +52,8 @@ func TestEtcd3Locker(t *testing.T) {
locker2, err := NewWithPrefix(client, testPrefix)
a.NoError(err)
a.NoError(locker2.LockUpload("one"))
a.Equal(tusd.ErrFileLocked, locker2.LockUpload("one"))
a.Equal(tusd.ErrFileLocked, locker2.LockUpload("one"))
a.Equal(handler.ErrFileLocked, locker2.LockUpload("one"))
a.Equal(handler.ErrFileLocked, locker2.LockUpload("one"))
a.NoError(locker2.UnlockUpload("one"))
a.Equal(ErrLockNotHeld, locker2.UnlockUpload("one"))
}

View File

@ -1,6 +1,6 @@
// Package filestore provide a storage backend based on the local file system.
//
// FileStore is a storage backend used as a tusd.DataStore in tusd.NewHandler.
// FileStore is a storage backend used as a handler.DataStore in handler.NewHandler.
// It stores the uploads in a directory specified in two different files: The
// `[id].info` files are used to store the fileinfo in JSON format. The
// `[id].bin` files contain the raw binary data uploaded.
@ -11,7 +11,7 @@
// which are stored on disk. Each of them stores the PID of the process which
// acquired the lock. This allows locks to be automatically freed when a process
// is unable to release it on its own because the process is not alive anymore.
// For more information, consult the documentation for tusd.LockerDataStore
// For more information, consult the documentation for handler.LockerDataStore
// interface, which is implemented by FileStore
package filestore
@ -23,15 +23,15 @@ import (
"os"
"path/filepath"
"github.com/tus/tusd"
"github.com/tus/tusd/uid"
"github.com/tus/tusd/internal/uid"
"github.com/tus/tusd/pkg/handler"
"gopkg.in/Acconut/lockfile.v1"
)
var defaultFilePerm = os.FileMode(0664)
// See the tusd.DataStore interface for documentation about the different
// See the handler.DataStore interface for documentation about the different
// methods.
type FileStore struct {
// Relative or absolute path to store files in. FileStore does not check
@ -49,7 +49,7 @@ func New(path string) FileStore {
// UseIn sets this store as the core data store in the passed composer and adds
// all possible extension to it.
func (store FileStore) UseIn(composer *tusd.StoreComposer) {
func (store FileStore) UseIn(composer *handler.StoreComposer) {
composer.UseCore(store)
composer.UseGetReader(store)
composer.UseTerminater(store)
@ -58,7 +58,7 @@ func (store FileStore) UseIn(composer *tusd.StoreComposer) {
composer.UseLengthDeferrer(store)
}
func (store FileStore) NewUpload(info tusd.FileInfo) (id string, err error) {
func (store FileStore) NewUpload(info handler.FileInfo) (id string, err error) {
id = uid.Uid()
info.ID = id
@ -97,8 +97,8 @@ func (store FileStore) WriteChunk(id string, offset int64, src io.Reader) (int64
return n, err
}
func (store FileStore) GetInfo(id string) (tusd.FileInfo, error) {
info := tusd.FileInfo{}
func (store FileStore) GetInfo(id string) (handler.FileInfo, error) {
info := handler.FileInfo{}
data, err := ioutil.ReadFile(store.infoPath(id))
if err != nil {
return info, err
@ -170,7 +170,7 @@ func (store FileStore) LockUpload(id string) error {
err = lock.TryLock()
if err == lockfile.ErrBusy {
return tusd.ErrFileLocked
return handler.ErrFileLocked
}
return err
@ -218,7 +218,7 @@ func (store FileStore) infoPath(id string) string {
}
// writeInfo updates the entire information. Everything will be overwritten.
func (store FileStore) writeInfo(id string, info tusd.FileInfo) error {
func (store FileStore) writeInfo(id string, info handler.FileInfo) error {
data, err := json.Marshal(info)
if err != nil {
return err

View File

@ -9,16 +9,16 @@ import (
"github.com/stretchr/testify/assert"
"github.com/tus/tusd"
"github.com/tus/tusd/pkg/handler"
)
// Test interface implementation of Filestore
var _ tusd.DataStore = FileStore{}
var _ tusd.GetReaderDataStore = FileStore{}
var _ tusd.TerminaterDataStore = FileStore{}
var _ tusd.LockerDataStore = FileStore{}
var _ tusd.ConcaterDataStore = FileStore{}
var _ tusd.LengthDeferrerDataStore = FileStore{}
var _ handler.DataStore = FileStore{}
var _ handler.GetReaderDataStore = FileStore{}
var _ handler.TerminaterDataStore = FileStore{}
var _ handler.LockerDataStore = FileStore{}
var _ handler.ConcaterDataStore = FileStore{}
var _ handler.LengthDeferrerDataStore = FileStore{}
func TestFilestore(t *testing.T) {
a := assert.New(t)
@ -29,7 +29,7 @@ func TestFilestore(t *testing.T) {
store := FileStore{tmp}
// Create new upload
id, err := store.NewUpload(tusd.FileInfo{
id, err := store.NewUpload(handler.FileInfo{
Size: 42,
MetaData: map[string]string{
"hello": "world",
@ -43,7 +43,7 @@ func TestFilestore(t *testing.T) {
a.NoError(err)
a.EqualValues(42, info.Size)
a.EqualValues(0, info.Offset)
a.Equal(tusd.MetaData{"hello": "world"}, info.MetaData)
a.Equal(handler.MetaData{"hello": "world"}, info.MetaData)
// Write data to upload
bytesWritten, err := store.WriteChunk(id, 0, strings.NewReader("hello world"))
@ -78,7 +78,7 @@ func TestMissingPath(t *testing.T) {
store := FileStore{"./path-that-does-not-exist"}
id, err := store.NewUpload(tusd.FileInfo{})
id, err := store.NewUpload(handler.FileInfo{})
a.Error(err)
a.Equal(err.Error(), "upload directory does not exist: ./path-that-does-not-exist")
a.Equal(id, "")
@ -90,11 +90,11 @@ func TestFileLocker(t *testing.T) {
dir, err := ioutil.TempDir("", "tusd-file-locker")
a.NoError(err)
var locker tusd.LockerDataStore
var locker handler.LockerDataStore
locker = FileStore{dir}
a.NoError(locker.LockUpload("one"))
a.Equal(tusd.ErrFileLocked, locker.LockUpload("one"))
a.Equal(handler.ErrFileLocked, locker.LockUpload("one"))
a.NoError(locker.UnlockUpload("one"))
}
@ -107,7 +107,7 @@ func TestConcatUploads(t *testing.T) {
store := FileStore{tmp}
// Create new upload to hold concatenated upload
finId, err := store.NewUpload(tusd.FileInfo{Size: 9})
finId, err := store.NewUpload(handler.FileInfo{Size: 9})
a.NoError(err)
a.NotEqual("", finId)
@ -119,7 +119,7 @@ func TestConcatUploads(t *testing.T) {
"ghi",
}
for i := 0; i < 3; i++ {
id, err := store.NewUpload(tusd.FileInfo{Size: 3})
id, err := store.NewUpload(handler.FileInfo{Size: 3})
a.NoError(err)
n, err := store.WriteChunk(id, 0, strings.NewReader(contents[i]))
@ -156,7 +156,7 @@ func TestDeclareLength(t *testing.T) {
store := FileStore{tmp}
originalInfo := tusd.FileInfo{Size: 0, SizeIsDeferred: true}
originalInfo := handler.FileInfo{Size: 0, SizeIsDeferred: true}
id, err := store.NewUpload(originalInfo)
a.NoError(err)

View File

@ -8,7 +8,7 @@ import (
"gopkg.in/h2non/gock.v1"
"cloud.google.com/go/storage"
. "github.com/tus/tusd/gcsstore"
. "github.com/tus/tusd/pkg/gcsstore"
"google.golang.org/api/option"
)

View File

@ -22,11 +22,11 @@ import (
"sync/atomic"
"cloud.google.com/go/storage"
"github.com/tus/tusd"
"github.com/tus/tusd/uid"
"github.com/tus/tusd/internal/uid"
"github.com/tus/tusd/pkg/handler"
)
// See the tusd.DataStore interface for documentation about the different
// See the handler.DataStore interface for documentation about the different
// methods.
type GCSStore struct {
// Specifies the GCS bucket that uploads will be stored in
@ -51,14 +51,14 @@ func New(bucket string, service GCSAPI) GCSStore {
}
}
func (store GCSStore) UseIn(composer *tusd.StoreComposer) {
func (store GCSStore) UseIn(composer *handler.StoreComposer) {
composer.UseCore(store)
composer.UseTerminater(store)
composer.UseFinisher(store)
composer.UseGetReader(store)
}
func (store GCSStore) NewUpload(info tusd.FileInfo) (id string, err error) {
func (store GCSStore) NewUpload(info handler.FileInfo) (id string, err error) {
if info.ID == "" {
info.ID = uid.Uid()
}
@ -115,8 +115,8 @@ func (store GCSStore) WriteChunk(id string, offset int64, src io.Reader) (int64,
const CONCURRENT_SIZE_REQUESTS = 32
func (store GCSStore) GetInfo(id string) (tusd.FileInfo, error) {
info := tusd.FileInfo{}
func (store GCSStore) GetInfo(id string) (handler.FileInfo, error) {
info := handler.FileInfo{}
i := fmt.Sprintf("%s.info", store.keyWithPrefix(id))
params := GCSObjectParams{
@ -128,7 +128,7 @@ func (store GCSStore) GetInfo(id string) (tusd.FileInfo, error) {
r, err := store.Service.ReadObject(ctx, params)
if err != nil {
if err == storage.ErrObjectNotExist {
return info, tusd.ErrNotFound
return info, handler.ErrNotFound
}
return info, err
}
@ -213,7 +213,7 @@ func (store GCSStore) GetInfo(id string) (tusd.FileInfo, error) {
return info, nil
}
func (store GCSStore) writeInfo(ctx context.Context, id string, info tusd.FileInfo) error {
func (store GCSStore) writeInfo(ctx context.Context, id string, info handler.FileInfo) error {
data, err := json.Marshal(info)
if err != nil {
return err

View File

@ -1,12 +1,12 @@
// Automatically generated by MockGen. DO NOT EDIT!
// Source: github.com/tus/tusd/gcsstore (interfaces: GCSReader,GCSAPI)
// Source: github.com/tus/tusd/pkg/gcsstore (interfaces: GCSReader,GCSAPI)
package gcsstore_test
import (
context "context"
gomock "github.com/golang/mock/gomock"
gcsstore "github.com/tus/tusd/gcsstore"
gcsstore "github.com/tus/tusd/pkg/gcsstore"
io "io"
)

View File

@ -11,11 +11,11 @@ import (
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"github.com/tus/tusd"
"github.com/tus/tusd/gcsstore"
"github.com/tus/tusd/pkg/gcsstore"
"github.com/tus/tusd/pkg/handler"
)
// go:generate mockgen -destination=./gcsstore_mock_test.go -package=gcsstore_test github.com/tus/tusd/gcsstore GCSReader,GCSAPI
// go:generate mockgen -destination=./gcsstore_mock_test.go -package=gcsstore_test github.com/tus/tusd/pkg/gcsstore GCSReader,GCSAPI
const mockID = "123456789abcdefghijklmnopqrstuvwxyz"
const mockBucket = "bucket"
@ -23,7 +23,7 @@ const mockSize = 1337
const mockReaderData = "helloworld"
var mockTusdInfoJson = fmt.Sprintf(`{"ID":"%s","Size":%d,"MetaData":{"foo":"bar"}}`, mockID, mockSize)
var mockTusdInfo = tusd.FileInfo{
var mockTusdInfo = handler.FileInfo{
ID: mockID,
Size: mockSize,
MetaData: map[string]string{
@ -201,7 +201,7 @@ func TestGetInfoNotFound(t *testing.T) {
)
_, err := store.GetInfo(mockID)
assert.Equal(tusd.ErrNotFound, err)
assert.Equal(handler.ErrNotFound, err)
}
type MockGetReader struct{}
@ -368,7 +368,7 @@ func TestFinishUpload(t *testing.T) {
}
var mockTusdChunk0InfoJson = fmt.Sprintf(`{"ID":"%s","Size":%d,"Offset":%d,"MetaData":{"foo":"bar"}}`, mockID, mockSize, mockSize/3)
var mockTusdChunk1Info = tusd.FileInfo{
var mockTusdChunk1Info = handler.FileInfo{
ID: mockID,
Size: mockSize,
Offset: 455,

View File

@ -1,4 +1,4 @@
package tusd
package handler
// StoreComposer represents a composable data store. It consists of the core
// data store and optional extensions. Please consult the package's overview

View File

@ -1,4 +1,4 @@
package tusd
package handler
#define USE_FUNC(TYPE) \
func (store *StoreComposer) Use ## TYPE(ext TYPE ## DataStore) { \

View File

@ -0,0 +1,23 @@
package handler_test
import (
"github.com/tus/tusd/pkg/filestore"
"github.com/tus/tusd/pkg/handler"
"github.com/tus/tusd/pkg/memorylocker"
)
func ExampleNewStoreComposer() {
composer := handler.NewStoreComposer()
fs := filestore.New("./data")
fs.UseIn(composer)
ml := memorylocker.New()
ml.UseIn(composer)
config := handler.Config{
StoreComposer: composer,
}
_, _ = handler.NewHandler(config)
}

View File

@ -1,4 +1,4 @@
package tusd_test
package handler_test
import (
"net/http"
@ -8,7 +8,7 @@ import (
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
. "github.com/tus/tusd"
. "github.com/tus/tusd/pkg/handler"
)
func TestConcat(t *testing.T) {

View File

@ -1,4 +1,4 @@
package tusd
package handler
import (
"errors"

View File

@ -1,4 +1,4 @@
package tusd
package handler
import (
"io"

View File

@ -1,11 +1,11 @@
package tusd_test
package handler_test
import (
"net/http"
"net/http/httptest"
"testing"
. "github.com/tus/tusd"
. "github.com/tus/tusd/pkg/handler"
)
func TestCORS(t *testing.T) {

View File

@ -1,4 +1,4 @@
package tusd
package handler
import (
"context"

View File

@ -1,5 +1,5 @@
/*
Package tusd provides ways to accept tus 1.0 calls using HTTP.
Package handler provides ways to accept tus 1.0 calls using HTTP.
tus is a protocol based on HTTP for resumable file uploads. Resumable means that
an upload can be interrupted at any moment and can be resumed without
@ -66,4 +66,4 @@ This handler can then be mounted to a specific path, e.g. /files:
http.Handle("/files/", http.StripPrefix("/files/", handler))
*/
package tusd
package handler

View File

@ -1,4 +1,4 @@
package tusd_test
package handler_test
import (
"net/http"
@ -6,7 +6,7 @@ import (
"testing"
"github.com/golang/mock/gomock"
. "github.com/tus/tusd"
. "github.com/tus/tusd/pkg/handler"
)
type closingStringReader struct {

View File

@ -1,4 +1,4 @@
package tusd
package handler
import (
"net/http"

View File

@ -1,11 +1,11 @@
// Automatically generated by MockGen. DO NOT EDIT!
// Source: utils_test.go
package tusd_test
package handler_test
import (
gomock "github.com/golang/mock/gomock"
tusd "github.com/tus/tusd"
handler "github.com/tus/tusd/pkg/handler"
io "io"
)
@ -30,7 +30,7 @@ func (_m *MockFullDataStore) EXPECT() *_MockFullDataStoreRecorder {
return _m.recorder
}
func (_m *MockFullDataStore) NewUpload(info tusd.FileInfo) (string, error) {
func (_m *MockFullDataStore) NewUpload(info handler.FileInfo) (string, error) {
ret := _m.ctrl.Call(_m, "NewUpload", info)
ret0, _ := ret[0].(string)
ret1, _ := ret[1].(error)
@ -52,9 +52,9 @@ func (_mr *_MockFullDataStoreRecorder) WriteChunk(arg0, arg1, arg2 interface{})
return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteChunk", arg0, arg1, arg2)
}
func (_m *MockFullDataStore) GetInfo(id string) (tusd.FileInfo, error) {
func (_m *MockFullDataStore) GetInfo(id string) (handler.FileInfo, error) {
ret := _m.ctrl.Call(_m, "GetInfo", id)
ret0, _ := ret[0].(tusd.FileInfo)
ret0, _ := ret[0].(handler.FileInfo)
ret1, _ := ret[1].(error)
return ret0, ret1
}

View File

@ -1,4 +1,4 @@
package tusd_test
package handler_test
import (
"net/http"
@ -6,7 +6,7 @@ import (
"testing"
"github.com/golang/mock/gomock"
. "github.com/tus/tusd"
. "github.com/tus/tusd/pkg/handler"
)
func TestHead(t *testing.T) {

View File

@ -1,4 +1,4 @@
package tusd
package handler
import (
"log"

View File

@ -1,4 +1,4 @@
package tusd
package handler
import (
"errors"

View File

@ -1,10 +1,10 @@
package tusd_test
package handler_test
import (
"net/http"
"testing"
. "github.com/tus/tusd"
. "github.com/tus/tusd/pkg/handler"
)
func TestOptions(t *testing.T) {

View File

@ -1,4 +1,4 @@
package tusd_test
package handler_test
import (
"io"
@ -12,7 +12,7 @@ import (
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
. "github.com/tus/tusd"
. "github.com/tus/tusd/pkg/handler"
)
func TestPatch(t *testing.T) {

View File

@ -1,4 +1,4 @@
package tusd_test
package handler_test
import (
"bytes"
@ -9,7 +9,7 @@ import (
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
. "github.com/tus/tusd"
. "github.com/tus/tusd/pkg/handler"
)
func TestPost(t *testing.T) {

View File

@ -1,4 +1,4 @@
package tusd_test
package handler_test
import (
"testing"

View File

@ -1,11 +1,11 @@
package tusd_test
package handler_test
import (
"net/http"
"testing"
"github.com/golang/mock/gomock"
. "github.com/tus/tusd"
. "github.com/tus/tusd/pkg/handler"
"github.com/stretchr/testify/assert"
)

View File

@ -1,4 +1,4 @@
package tusd
package handler
import (
"context"

View File

@ -1,4 +1,4 @@
package tusd_test
package handler_test
import (
"fmt"
@ -10,10 +10,10 @@ import (
"testing"
"github.com/golang/mock/gomock"
"github.com/tus/tusd"
"github.com/tus/tusd/pkg/handler"
)
//go:generate mockgen -package tusd_test -source utils_test.go -aux_files tusd=datastore.go -destination=handler_mock_test.go
//go:generate mockgen -package handler_test -source utils_test.go -aux_files tusd=datastore.go -destination=handler_mock_test.go
// FullDataStore is an interface combining most interfaces for data stores.
// This is used by mockgen(1) to generate a mocked data store used for testing
@ -22,16 +22,16 @@ import (
// locking in every single test which would result in more verbose code.
// Therefore it has been moved into its own type definition, the Locker.
type FullDataStore interface {
tusd.DataStore
tusd.TerminaterDataStore
tusd.ConcaterDataStore
tusd.GetReaderDataStore
tusd.FinisherDataStore
tusd.LengthDeferrerDataStore
handler.DataStore
handler.TerminaterDataStore
handler.ConcaterDataStore
handler.GetReaderDataStore
handler.FinisherDataStore
handler.LengthDeferrerDataStore
}
type Locker interface {
tusd.LockerDataStore
handler.LockerDataStore
}
type httpTest struct {

View File

@ -13,7 +13,7 @@ package memorylocker
import (
"sync"
"github.com/tus/tusd"
"github.com/tus/tusd/pkg/handler"
)
// MemoryLocker persists locks using memory and therefore allowing a simple and
@ -27,7 +27,7 @@ type MemoryLocker struct {
// NewMemoryLocker creates a new in-memory locker. The DataStore parameter
// is only presented for back-wards compatibility and is ignored. Please
// use the New() function instead.
func NewMemoryLocker(_ tusd.DataStore) *MemoryLocker {
func NewMemoryLocker(_ handler.DataStore) *MemoryLocker {
return New()
}
@ -39,7 +39,7 @@ func New() *MemoryLocker {
}
// UseIn adds this locker to the passed composer.
func (locker *MemoryLocker) UseIn(composer *tusd.StoreComposer) {
func (locker *MemoryLocker) UseIn(composer *handler.StoreComposer) {
composer.UseLocker(locker)
}
@ -50,7 +50,7 @@ func (locker *MemoryLocker) LockUpload(id string) error {
// Ensure file is not locked
if _, ok := locker.locks[id]; ok {
return tusd.ErrFileLocked
return handler.ErrFileLocked
}
locker.locks[id] = struct{}{}

View File

@ -5,17 +5,17 @@ import (
"github.com/stretchr/testify/assert"
"github.com/tus/tusd"
"github.com/tus/tusd/pkg/handler"
)
func TestMemoryLocker(t *testing.T) {
a := assert.New(t)
var locker tusd.LockerDataStore
var locker handler.LockerDataStore
locker = New()
a.NoError(locker.LockUpload("one"))
a.Equal(tusd.ErrFileLocked, locker.LockUpload("one"))
a.Equal(handler.ErrFileLocked, locker.LockUpload("one"))
a.NoError(locker.UnlockUpload("one"))
a.NoError(locker.UnlockUpload("one"))
}

View File

@ -3,7 +3,7 @@
// Using the provided collector, you can easily expose metrics for tusd in the
// Prometheus exposition format (https://prometheus.io/docs/instrumenting/exposition_formats/):
//
// handler, err := tusd.NewHandler(…)
// handler, err := handler.NewHandler(…)
// collector := prometheuscollector.New(handler.Metrics)
// prometheus.MustRegister(collector)
package prometheuscollector
@ -12,7 +12,7 @@ import (
"strconv"
"sync/atomic"
"github.com/tus/tusd"
"github.com/tus/tusd/pkg/handler"
"github.com/prometheus/client_golang/prometheus"
)
@ -45,11 +45,11 @@ var (
)
type Collector struct {
metrics tusd.Metrics
metrics handler.Metrics
}
// New creates a new collector which read froms the provided Metrics struct.
func New(metrics tusd.Metrics) Collector {
func New(metrics handler.Metrics) Collector {
return Collector{
metrics: metrics,
}

View File

@ -65,7 +65,7 @@
// consistency (https://docs.aws.amazon.com/AmazonS3/latest/dev/Introduction.html#ConsistencyModel).
// Therefore, it is required to build additional measurements in order to
// prevent concurrent access to the same upload resources which may result in
// data corruption. See tusd.LockerDataStore for more information.
// data corruption. See handler.LockerDataStore for more information.
package s3store
import (
@ -80,8 +80,8 @@ import (
"strings"
"sync"
"github.com/tus/tusd"
"github.com/tus/tusd/uid"
"github.com/tus/tusd/internal/uid"
"github.com/tus/tusd/pkg/handler"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
@ -92,7 +92,7 @@ import (
// ASCII tables which range from 00 to 7F, inclusive.
var nonASCIIRegexp = regexp.MustCompile(`([^\x00-\x7F])`)
// See the tusd.DataStore interface for documentation about the different
// See the handler.DataStore interface for documentation about the different
// methods.
type S3Store struct {
// Bucket used to store the data in, e.g. "tusdstore.example.com"
@ -157,7 +157,7 @@ func New(bucket string, service S3API) S3Store {
// UseIn sets this store as the core data store in the passed composer and adds
// all possible extension to it.
func (store S3Store) UseIn(composer *tusd.StoreComposer) {
func (store S3Store) UseIn(composer *handler.StoreComposer) {
composer.UseCore(store)
composer.UseTerminater(store)
composer.UseFinisher(store)
@ -166,7 +166,7 @@ func (store S3Store) UseIn(composer *tusd.StoreComposer) {
composer.UseLengthDeferrer(store)
}
func (store S3Store) NewUpload(info tusd.FileInfo) (id string, err error) {
func (store S3Store) NewUpload(info handler.FileInfo) (id string, err error) {
// an upload larger than MaxObjectSize must throw an error
if info.Size > store.MaxObjectSize {
return "", fmt.Errorf("s3store: upload size of %v bytes exceeds MaxObjectSize of %v bytes", info.Size, store.MaxObjectSize)
@ -210,7 +210,7 @@ func (store S3Store) NewUpload(info tusd.FileInfo) (id string, err error) {
return id, nil
}
func (store S3Store) writeInfo(uploadId string, info tusd.FileInfo) error {
func (store S3Store) writeInfo(uploadId string, info handler.FileInfo) error {
infoJson, err := json.Marshal(info)
if err != nil {
return err
@ -328,7 +328,7 @@ func (store S3Store) WriteChunk(id string, offset int64, src io.Reader) (int64,
}
}
func (store S3Store) GetInfo(id string) (info tusd.FileInfo, err error) {
func (store S3Store) GetInfo(id string) (info handler.FileInfo, err error) {
uploadId, _ := splitIds(id)
// Get file info stored in separate object
@ -338,7 +338,7 @@ func (store S3Store) GetInfo(id string) (info tusd.FileInfo, err error) {
})
if err != nil {
if isAwsError(err, "NoSuchKey") {
return info, tusd.ErrNotFound
return info, handler.ErrNotFound
}
return info, err
@ -418,7 +418,7 @@ func (store S3Store) GetReader(id string) (io.Reader, error) {
if isAwsError(err, "NoSuchUpload") {
// Neither the object nor the multipart upload exists, so we return a 404
return nil, tusd.ErrNotFound
return nil, handler.ErrNotFound
}
return nil, err

View File

@ -1,5 +1,5 @@
// Automatically generated by MockGen. DO NOT EDIT!
// Source: github.com/tus/tusd/s3store (interfaces: S3API)
// Source: github.com/tus/tusd/pkg/s3store (interfaces: S3API)
package s3store

View File

@ -13,17 +13,17 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/tus/tusd"
"github.com/tus/tusd/pkg/handler"
)
//go:generate mockgen -destination=./s3store_mock_test.go -package=s3store github.com/tus/tusd/s3store S3API
//go:generate mockgen -destination=./s3store_mock_test.go -package=s3store github.com/tus/tusd/pkg/s3store S3API
// Test interface implementations
var _ tusd.DataStore = S3Store{}
var _ tusd.GetReaderDataStore = S3Store{}
var _ tusd.TerminaterDataStore = S3Store{}
var _ tusd.FinisherDataStore = S3Store{}
var _ tusd.ConcaterDataStore = S3Store{}
var _ handler.DataStore = S3Store{}
var _ handler.GetReaderDataStore = S3Store{}
var _ handler.TerminaterDataStore = S3Store{}
var _ handler.FinisherDataStore = S3Store{}
var _ handler.ConcaterDataStore = S3Store{}
func TestNewUpload(t *testing.T) {
mockCtrl := gomock.NewController(t)
@ -58,7 +58,7 @@ func TestNewUpload(t *testing.T) {
}),
)
info := tusd.FileInfo{
info := handler.FileInfo{
ID: "uploadId",
Size: 500,
MetaData: map[string]string{
@ -106,7 +106,7 @@ func TestNewUploadWithObjectPrefix(t *testing.T) {
}),
)
info := tusd.FileInfo{
info := handler.FileInfo{
ID: "uploadId",
Size: 500,
MetaData: map[string]string{
@ -131,7 +131,7 @@ func TestNewUploadLargerMaxObjectSize(t *testing.T) {
assert.Equal("bucket", store.Bucket)
assert.Equal(s3obj, store.Service)
info := tusd.FileInfo{
info := handler.FileInfo{
ID: "uploadId",
Size: store.MaxObjectSize + 1,
}
@ -156,7 +156,7 @@ func TestGetInfoNotFound(t *testing.T) {
}).Return(nil, awserr.New("NoSuchKey", "The specified key does not exist.", nil))
_, err := store.GetInfo("uploadId+multipartId")
assert.Equal(tusd.ErrNotFound, err)
assert.Equal(handler.ErrNotFound, err)
}
func TestGetInfo(t *testing.T) {
@ -243,8 +243,8 @@ func TestGetInfoWithIncompletePart(t *testing.T) {
Bucket: aws.String("bucket"),
Key: aws.String("uploadId.part"),
}).Return(&s3.GetObjectOutput{
ContentLength: aws.Int64(10),
Body: ioutil.NopCloser(bytes.NewReader([]byte("0123456789"))),
ContentLength: aws.Int64(10),
Body: ioutil.NopCloser(bytes.NewReader([]byte("0123456789"))),
}, nil),
)
@ -326,7 +326,7 @@ func TestGetReaderNotFound(t *testing.T) {
content, err := store.GetReader("uploadId+multipartId")
assert.Nil(content)
assert.Equal(tusd.ErrNotFound, err)
assert.Equal(handler.ErrNotFound, err)
}
func TestGetReaderNotFinished(t *testing.T) {
@ -730,8 +730,8 @@ func TestWriteChunkPrependsIncompletePart(t *testing.T) {
Bucket: aws.String("bucket"),
Key: aws.String("uploadId.part"),
}).Return(&s3.GetObjectOutput{
ContentLength: aws.Int64(3),
Body: ioutil.NopCloser(bytes.NewReader([]byte("123"))),
ContentLength: aws.Int64(3),
Body: ioutil.NopCloser(bytes.NewReader([]byte("123"))),
}, nil),
s3obj.EXPECT().ListParts(&s3.ListPartsInput{
Bucket: aws.String("bucket"),

View File

@ -1,8 +0,0 @@
{
"folders": [
{
"path": "."
}
],
"settings": {}
}