/
types.go
186 lines (156 loc) · 6.35 KB
/
types.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
package protocol
import (
"github.com/materials-commons/mcfs/base/mcerr"
"time"
)
const (
// LoginRequest LoginReq
LoginRequest uint8 = iota
// LoginResponse LoginResp
LoginResponse
// LogoutRequest LogoutReq
LogoutRequest
// CreateProjectRequest CreateProjectReq
CreateProjectRequest
// CreateProjectResponse CreateProjectResp
CreateProjectResponse
// CreateDirectoryRequest CreateDirectoryReq
CreateDirectoryRequest
// CreateDirectoryResponse CreateDirectoryResp
CreateDirectoryResponse
// CreateFileRequest CreateFileReq
CreateFileRequest
// CreateFileResponse CreateFileResp
CreateFileResponse
// DirectoryStatRequest DirectoryStatReq
DirectoryStatRequest
// DirectoryStatResponse DirectoryStatResp
DirectoryStatResponse
// SendBytesRequest SendBytesReq
SendBytesRequest
)
// Status is the status of the request. All response type messages include a request status.
// This denotes success or failure of the request. On failure a message with additional details
// may be included.
type Status struct {
Status mcerr.ErrorCode // Error code (can be translated to an error)
Message string // Additional status message
}
// LoginReq is sent to login to the server and prepare to issue commands.
type LoginReq struct {
User string // User login, usually their email address
APIKey string // The APIKey the server holds
}
// LoginResp will inform the client whether the login request was successful.
type LoginResp struct {
Status
}
// LogoutReq is sent to end a session and disconnect. There client doesn't wait for
// a response from the server. It terminates the connection after sending this request.
type LogoutReq struct {
}
// CreateProjectReq is sent to create a project.
// If shared is set to true then the server will check if a project
// matching this name exists in any of the projects user has access to. If so
// it will use that project.
type CreateProjectReq struct {
Name string // The name of the project to create
Shared bool // Should we check shared projects?
}
// CreateProjectResp is the response to a CreateProjectRequest. A request to create
// a project will not create a project if a matching project already exists. In that case
// it will indicate this in the Status field.
//
// The status of the request. There are two error codes for success:
// ErrorCodeSuccess - Project was created
// ErrorCodeExists - Project already exists
// All other error codes are failures.
type CreateProjectResp struct {
Status Status // Request status
ProjectID string // The internal ProjectID for the created or existing project.
DirectoryID string // The internal id for the directory that the project is stored in.
}
// CreateDirectoryReq is sent to create a directory in a project.
type CreateDirectoryReq struct {
ProjectID string // The project to create the directory in.
Path string // The directory path, relative to the project to create. All members of the path except the leaf must exist.
}
// CreateDirectoryResp is the response for a CreateDirectoryRequest. A request to create
// a directory will not create a directory if a matching directory already exists. In
// that case it will indicate this in the Status field.
//
// The status of the request. There are two error codes for success:
// ErrorCodeSuccess - Directory was created
// ErrorCodeExists - Directory already exists
// All other error codes are failures.
type CreateDirectoryResp struct {
Status // Request status
DirectoryID string // The internal id of the directory.
}
// CreateFileReq is sent to create a new file on the server. It is expected that
// after this request is sent that an attempt will be made to upload the file. Until
// this upload succeeds newer versions of the file cannot be created.
//
// If CreateNewVersion is set to true then a new file version will
// be created if the previous file has already been successfully
// uploaded.
type CreateFileReq struct {
ProjectID string // The id of the project to create the file in.
DirectoryID string // The id of the directory in the project to create the file in.
Name string // The name of the file.
Checksum string // The files MD5 hash
Size int64 // The size of the file
CreateNewVersion bool // Should we create a new version
}
// CreateFileResp is the response to a CreateFileRequest.
//
// Status of the request. There are three error codes for success:
// ErrorCodeSuccess - File was created
// ErrorCodeExists - File already exists
// ErrorCodeNew - A new version of the file was created
// All other error codes are failures.
type CreateFileResp struct {
Status // Request status
FileID string // The internal id of the file.
}
// DirectoryStatReq requests the server to send back its current
// view of the given directory.
type DirectoryStatReq struct {
ProjectID string // Project ID on server that the directory is in
DirectoryID string // Directory ID on server
}
// StatEntryType identifies the type of stat entry as either a file
// or a directory.
type StatEntryType uint8
const (
// StatTypeDirectory entry is a directory
StatTypeDirectory StatEntryType = iota
// StatTypeFile entry is a file
StatTypeFile
)
// StatEntry describes a single file or directory.
//
// If Type is StatTypeDirectory, then Checksum, Size, and UploadedSize are not defined.
type StatEntry struct {
Type StatEntryType // The type of entry
Name string // Name of entry
ID string // The internal ID of the entry
Owner string // Owner of entry
Checksum string // The computed MD5 Hash
Size int64 // The size of the file
UploadedSize int64 // The actual uploaded size of the file
Birthtime time.Time // Datetime the entry was created on the server.
}
// DirectoryStatResp is the response for a DirectoryStatRequest. It returns
// a list of all the known entries in the directory.
type DirectoryStatResp struct {
Status // Status of the request
ProjectID string // ProjectID passed in the request
DirectoryID string // DirectoryID passed in the request
Entries []StatEntry // A list of all the entries for this directory.
}
// SendBytesReq contains the bytes to write.
type SendBytesReq struct {
FileID string // File ID on the server that these bytes are for
Bytes []byte // The set of bytes to write
}