-
Notifications
You must be signed in to change notification settings - Fork 4
/
api.go
93 lines (78 loc) · 2.02 KB
/
api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package storage
// Look here for various implementations:
// https://github.com/puppetlabs/nebula-libs/tree/master/storage"
//
import (
"context"
"fmt"
"io"
)
type ErrorCode string
const (
AuthError ErrorCode = "AuthError"
NotFoundError ErrorCode = "NotFoundError"
TimeoutError ErrorCode = "TimeoutError"
UnknownError ErrorCode = "UnknownError"
)
type errorImpl struct {
message string
code ErrorCode
cause error
}
func (e *errorImpl) Error() string {
return e.message
}
func (e *errorImpl) Unwrap() error {
return e.cause
}
func Errorf(cause error, code ErrorCode, format string, a ...interface{}) error {
return &errorImpl{
code: code,
message: fmt.Sprintf(format, a...),
cause: cause,
}
}
func IsAuthError(err error) bool {
e, ok := err.(*errorImpl)
return ok && e.code == AuthError
}
func IsNotFoundError(err error) bool {
e, ok := err.(*errorImpl)
return ok && e.code == NotFoundError
}
func IsTimeoutError(err error) bool {
e, ok := err.(*errorImpl)
return ok && e.code == TimeoutError
}
type Sink func(io.Writer) error
type Source func(*Meta, io.Reader) error
type Meta struct {
// ContentType of the blob
ContentType string
// Offset within the blob that the read begins
Offset int64
// Size is the total size of the blob
Size int64
}
type PutOptions struct {
// ContentType of the blob
ContentType string
}
type GetOptions struct {
// Offset is the byte offset to begin at, it may be negative
// to specify an offset from the end of the blob.
Offset int64
// Length is the maximum number of bytes to return, if <= 0
// then all bytes after Offset are returned. The Length must
// be <= 0 if Offset is negative due to the limitations of
// HTTP range requests.
Length int64
}
type DeleteOptions struct {
// TODO: Support conditional deletes?
}
type BlobStore interface {
Put(ctx context.Context, key string, sink Sink, opts PutOptions) error
Get(ctx context.Context, key string, source Source, opts GetOptions) error
Delete(ctx context.Context, key string, opts DeleteOptions) error
}