diff options
author | Pacien TRAN-GIRARD | 2012-09-08 14:02:56 +0200 |
---|---|---|
committer | Pacien | 2015-12-07 22:48:22 +0100 |
commit | c5a9744b87354f67e219ee0069180a94ed27c3ee (patch) | |
tree | 51327c79a2e5cfe2c74c0a4d704f18affdaa1a44 | |
parent | 13482ad673640b281dd2de46a66a60a54d280fc7 (diff) | |
download | ninja-go-local-cloud-c5a9744b87354f67e219ee0069180a94ed27c3ee.tar.gz |
First draft: program structure.
-rw-r--r-- | File IO REST API Spec.html | 881 | ||||
-rw-r--r-- | src/ninjacloud.go | 145 |
2 files changed, 1026 insertions, 0 deletions
diff --git a/File IO REST API Spec.html b/File IO REST API Spec.html new file mode 100644 index 0000000..289359e --- /dev/null +++ b/File IO REST API Spec.html | |||
@@ -0,0 +1,881 @@ | |||
1 | <!DOCTYPE html> | ||
2 | <!-- <copyright> | ||
3 | Copyright (c) 2012, Motorola Mobility LLC. | ||
4 | All Rights Reserved. | ||
5 | |||
6 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. | ||
9 | |||
10 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. | ||
11 | |||
12 | * Neither the name of Motorola Mobility LLC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. | ||
13 | |||
14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
15 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT | ||
16 | SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
17 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
18 | OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | ||
19 | TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
20 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
21 | </copyright> --> | ||
22 | <html> | ||
23 | <head> | ||
24 | <title>Ninja File IO Rest API Documentation.doc</title> | ||
25 | <style type="text/css">@import url('https://themes.googleusercontent.com/fonts/css?kit=MSSLfUayeNh9PW3ng9UWrirlBcGJ7N4dBtR9TI-y1vHA6mILqzkelCs0stqH5so2'); | ||
26 | |||
27 | ol { | ||
28 | margin: 0; | ||
29 | padding: 0 | ||
30 | } | ||
31 | |||
32 | p { | ||
33 | margin: 0 | ||
34 | } | ||
35 | |||
36 | .c5 { | ||
37 | vertical-align: top; | ||
38 | width: 108.9pt; | ||
39 | border-style: solid; | ||
40 | border-color: #000000; | ||
41 | border-width: 1pt; | ||
42 | padding: 0pt 5.4pt 0pt 5.4pt | ||
43 | } | ||
44 | |||
45 | .c12 { | ||
46 | vertical-align: top; | ||
47 | width: 447.8pt; | ||
48 | border-style: solid; | ||
49 | border-color: #000000; | ||
50 | border-width: 1pt; | ||
51 | padding: 0pt 5.4pt 0pt 5.4pt | ||
52 | } | ||
53 | |||
54 | .c4 { | ||
55 | vertical-align: top; | ||
56 | width: 106.8pt; | ||
57 | border-style: solid; | ||
58 | border-color: #000000; | ||
59 | border-width: 1pt; | ||
60 | padding: 0pt 5.4pt 0pt 5.4pt | ||
61 | } | ||
62 | |||
63 | .c7 { | ||
64 | vertical-align: top; | ||
65 | width: 445.5pt; | ||
66 | border-style: solid; | ||
67 | border-color: #000000; | ||
68 | border-width: 1pt; | ||
69 | padding: 0pt 5.4pt 0pt 5.4pt | ||
70 | } | ||
71 | |||
72 | .c6 { | ||
73 | vertical-align: top; | ||
74 | width: 445.7pt; | ||
75 | border-style: solid; | ||
76 | border-color: #000000; | ||
77 | border-width: 1pt; | ||
78 | padding: 0pt 5.4pt 0pt 5.4pt | ||
79 | } | ||
80 | |||
81 | .c0 { | ||
82 | line-height: 1.0; | ||
83 | direction: ltr; | ||
84 | padding-bottom: 0pt | ||
85 | } | ||
86 | |||
87 | .c18 { | ||
88 | font-size: 9pt; | ||
89 | font-family: Arial | ||
90 | } | ||
91 | |||
92 | .c17 { | ||
93 | max-width: 648pt; | ||
94 | padding: 72pt 72pt 72pt 72pt | ||
95 | } | ||
96 | |||
97 | .c14 { | ||
98 | font-size: 9pt; | ||
99 | font-family: Consolas | ||
100 | } | ||
101 | |||
102 | .c1 { | ||
103 | direction: ltr; | ||
104 | padding-bottom: 0pt | ||
105 | } | ||
106 | |||
107 | .c8 { | ||
108 | height: 0pt | ||
109 | } | ||
110 | |||
111 | .c11 { | ||
112 | height: 11pt | ||
113 | } | ||
114 | |||
115 | .c16 { | ||
116 | font-size: 16pt | ||
117 | } | ||
118 | |||
119 | .c3 { | ||
120 | text-decoration: underline | ||
121 | } | ||
122 | |||
123 | .c2 { | ||
124 | direction: ltr | ||
125 | } | ||
126 | |||
127 | .c13 { | ||
128 | background-color: #ffffff | ||
129 | } | ||
130 | |||
131 | .c15 { | ||
132 | border-collapse: collapse | ||
133 | } | ||
134 | |||
135 | .c9 { | ||
136 | margin-left: 36pt | ||
137 | } | ||
138 | |||
139 | .c10 { | ||
140 | font-style: italic | ||
141 | } | ||
142 | |||
143 | .title { | ||
144 | padding-top: 24pt; | ||
145 | line-height: 1.15; | ||
146 | text-align: left; | ||
147 | color: #000000; | ||
148 | font-size: 36pt; | ||
149 | font-family: Calibri; | ||
150 | font-weight: bold; | ||
151 | padding-bottom: 6pt | ||
152 | } | ||
153 | |||
154 | .subtitle { | ||
155 | padding-top: 18pt; | ||
156 | line-height: 1.15; | ||
157 | text-align: left; | ||
158 | color: #666666; | ||
159 | font-style: italic; | ||
160 | font-size: 24pt; | ||
161 | font-family: Georgia; | ||
162 | padding-bottom: 4pt | ||
163 | } | ||
164 | |||
165 | body { | ||
166 | color: #000000; | ||
167 | font-size: 11pt; | ||
168 | font-family: Calibri | ||
169 | } | ||
170 | |||
171 | h1 { | ||
172 | padding-top: 12pt; | ||
173 | line-height: 1.15; | ||
174 | text-align: left; | ||
175 | color: #000000; | ||
176 | font-size: 16pt; | ||
177 | font-family: Cambria; | ||
178 | font-weight: bold; | ||
179 | padding-bottom: 3pt | ||
180 | } | ||
181 | |||
182 | h2 { | ||
183 | padding-top: 12pt; | ||
184 | line-height: 1.15; | ||
185 | text-align: left; | ||
186 | color: #000000; | ||
187 | font-style: italic; | ||
188 | font-size: 14pt; | ||
189 | font-family: Cambria; | ||
190 | font-weight: bold; | ||
191 | padding-bottom: 3pt | ||
192 | } | ||
193 | |||
194 | h3 { | ||
195 | padding-top: 12pt; | ||
196 | line-height: 1.15; | ||
197 | text-align: left; | ||
198 | color: #000000; | ||
199 | font-size: 13pt; | ||
200 | font-family: Cambria; | ||
201 | font-weight: bold; | ||
202 | padding-bottom: 3pt | ||
203 | } | ||
204 | |||
205 | h4 { | ||
206 | padding-top: 12pt; | ||
207 | line-height: 1.15; | ||
208 | text-align: left; | ||
209 | color: #000000; | ||
210 | font-size: 14pt; | ||
211 | font-family: Calibri; | ||
212 | font-weight: bold; | ||
213 | padding-bottom: 3pt | ||
214 | } | ||
215 | |||
216 | h5 { | ||
217 | padding-top: 12pt; | ||
218 | line-height: 1.15; | ||
219 | text-align: left; | ||
220 | color: #000000; | ||
221 | font-style: italic; | ||
222 | font-size: 13pt; | ||
223 | font-family: Calibri; | ||
224 | font-weight: bold; | ||
225 | padding-bottom: 3pt | ||
226 | } | ||
227 | |||
228 | h6 { | ||
229 | padding-top: 12pt; | ||
230 | line-height: 1.15; | ||
231 | text-align: left; | ||
232 | color: #000000; | ||
233 | font-size: 11pt; | ||
234 | font-family: Calibri; | ||
235 | font-weight: bold; | ||
236 | padding-bottom: 3pt | ||
237 | }</style> | ||
238 | </head> | ||
239 | <body class="c13 c17"><h1 class="c2"><span>Cloud Status API</span></h1> | ||
240 | |||
241 | <p class="c1"><span>In order to determine if the ninja cloud is running for a particular server (local or remote), you can call</span> | ||
242 | </p> | ||
243 | |||
244 | <p class="c1"><span>http://<the server url>/cloudstatus</span></p> | ||
245 | |||
246 | <p class="c1"><span>if the cloud server is up and running it will return status code 200 and a json string as follows:</span> | ||
247 | </p> | ||
248 | |||
249 | <p class="c1"><span class="c13 c14">{"name":"Ninja Local Cloud","status": "running","server-root":"C:/Users/vpn847/Documents/Ninja Projects","version":"0.5.0.0"}</span> | ||
250 | </p> | ||
251 | |||
252 | <p class="c1 c11"><span></span></p> | ||
253 | |||
254 | <p class="c1"><span>The cloud name provides a user facing name for the particular cloud server.</span></p> | ||
255 | |||
256 | <h1 class="c2"><span>File APIs</span></h1> | ||
257 | |||
258 | <p class="c2"><span>These APIs deal with single files. The shell will be limited to acting on files in paths the user has permissions to read/write.</span> | ||
259 | </p> | ||
260 | |||
261 | <h3 class="c2"><span>Create a new file</span></h3> | ||
262 | <table cellpadding="0" cellspacing="0" class="c15"> | ||
263 | <tbody> | ||
264 | <tr class="c8"> | ||
265 | <td class="c4"><p class="c2"><span>URL</span></p></td> | ||
266 | <td class="c12"><p class="c2"><span>http://someURL.com/file/<filepath>/<filename ></span></p> | ||
267 | |||
268 | <p class="c2"><span>e.g. </span></p> | ||
269 | |||
270 | <p class="c2"> | ||
271 | <span>http://someURL.com/file</span><span>/c/users/jdoe/my%20documents/foo.html<br></span><span>http://someURL.com/file</span><span>/users/jdoe/documents/foo.html<br>NOTE: all file paths are case sensitive</span> | ||
272 | </p></td> | ||
273 | </tr> | ||
274 | <tr class="c8"> | ||
275 | <td class="c4"><p class="c2"><span>Method</span></p></td> | ||
276 | <td class="c12"><p class="c2"><span>POST</span></p></td> | ||
277 | </tr> | ||
278 | <tr class="c8"> | ||
279 | <td class="c4"><p class="c2"><span>Request Headers</span></p></td> | ||
280 | <td class="c12"><p class="c2"><span>none</span></p></td> | ||
281 | </tr> | ||
282 | <tr class="c8"> | ||
283 | <td class="c4"><p class="c2"><span>Request Body</span></p></td> | ||
284 | <td class="c12"><p class="c2"><span class="c3">Optional</span><span><br>Raw file contents with the appropriate content-type.<br>If the body is empty, the file will be created with no content.</span> | ||
285 | </p></td> | ||
286 | </tr> | ||
287 | <tr class="c8"> | ||
288 | <td class="c4"><p class="c2"><span>Response headers</span></p></td> | ||
289 | <td class="c12"><p class="c2"><span>Cache-Control: no-cache</span></p></td> | ||
290 | </tr> | ||
291 | <tr class="c8"> | ||
292 | <td class="c4"><p class="c2"><span>Response body</span></p></td> | ||
293 | <td class="c12"><p class="c2"><span>none</span></p></td> | ||
294 | </tr> | ||
295 | <tr class="c8"> | ||
296 | <td class="c4"><p class="c2"><span>Return Status Codes</span></p></td> | ||
297 | <td class="c12"><p class="c2"><span>201 “Created” – | ||
298 | File was created<br>400 “Bad Request” – the file was not able to be created because it exists already.<br>500 “Internal Server Error” – | ||
299 | the file was not able to be created.</span></p></td> | ||
300 | </tr> | ||
301 | </tbody> | ||
302 | </table> | ||
303 | <h3 class="c2"><span>Update an existing file (save over existing file)</span></h3> | ||
304 | <table cellpadding="0" cellspacing="0" class="c15"> | ||
305 | <tbody> | ||
306 | <tr class="c8"> | ||
307 | <td class="c5"><p class="c2"><span>URL</span></p></td> | ||
308 | <td class="c6"><p class="c2"> | ||
309 | <span>http://someURL.com/file</span><span>/<filepath>/<filename ></span></p></td> | ||
310 | </tr> | ||
311 | <tr class="c8"> | ||
312 | <td class="c5"><p class="c2"><span>Method</span></p></td> | ||
313 | <td class="c6"><p class="c2"><span>PUT</span></p></td> | ||
314 | </tr> | ||
315 | <tr class="c8"> | ||
316 | <td class="c5"><p class="c2"><span>Request Headers</span></p></td> | ||
317 | <td class="c6"><p class="c2"><span>none</span></p></td> | ||
318 | </tr> | ||
319 | <tr class="c8"> | ||
320 | <td class="c5"><p class="c2"><span>Request Body</span></p></td> | ||
321 | <td class="c6"><p class="c2"><span>Raw file contents with the appropriate content-type.</span></p></td> | ||
322 | </tr> | ||
323 | <tr class="c8"> | ||
324 | <td class="c5"><p class="c2"><span>Response Headers</span></p></td> | ||
325 | <td class="c6"><p class="c2"><span>Cache-Control: no-cache</span></p></td> | ||
326 | </tr> | ||
327 | <tr class="c8"> | ||
328 | <td class="c5"><p class="c2"><span>Response Body</span></p></td> | ||
329 | <td class="c6"><p class="c2"><span>None</span></p></td> | ||
330 | </tr> | ||
331 | <tr class="c8"> | ||
332 | <td class="c5"><p class="c2"><a href="#" name="id.edf4c7030e42"></a><span>Returns Status Codes</span></p></td> | ||
333 | <td class="c6"><p class="c2"><span>204 “No Content” – | ||
334 | File was saved<br>404 “Not found” – | ||
335 | the file at the indicated URI does not exist.<br>500 “Internal Server Error” – the file was not able to be saved.</span> | ||
336 | </p></td> | ||
337 | </tr> | ||
338 | </tbody> | ||
339 | </table> | ||
340 | <h3 class="c2"><span>Copy, Move of an existing file </span></h3> | ||
341 | <table cellpadding="0" cellspacing="0" class="c15"> | ||
342 | <tbody> | ||
343 | <tr class="c8"> | ||
344 | <td class="c5"><p class="c2"><span>URL</span></p></td> | ||
345 | <td class="c6"><p class="c2"> | ||
346 | <span>http://someURL.com/file</span><span>/<filepath>/<filename ></span></p></td> | ||
347 | </tr> | ||
348 | <tr class="c8"> | ||
349 | <td class="c5"><p class="c2"><span>Method</span></p></td> | ||
350 | <td class="c6"><p class="c2"><span>PUT</span></p></td> | ||
351 | </tr> | ||
352 | <tr class="c8"> | ||
353 | <td class="c5"><p class="c2"><span>Request Headers</span></p></td> | ||
354 | <td class="c6"><p class="c2"><span class="c3">Required</span><span><br></span><span class="c10">sourceURI</span><span><br>value= <source file path in same format as in the URL><br>e.g. c/users/jdoe/my%20documents/foo.html</span> | ||
355 | </p> | ||
356 | |||
357 | <p class="c2"><span class="c3">Optional</span><span><br></span><span | ||
358 | class="c10">overwrite-destination</span><span><br>value=true/false<br>default=false<br>true indicates that it is safe to overwrite the destination file if it exists</span> | ||
359 | </p> | ||
360 | |||
361 | <p class="c2"><span class="c10">delete-source<br></span><span>value: true/false<br>default: false<br>true means to remove he source after the copy operation succeeds.</span> | ||
362 | </p></td> | ||
363 | </tr> | ||
364 | <tr class="c8"> | ||
365 | <td class="c5"><p class="c2"><span>Request Body</span></p></td> | ||
366 | <td class="c6"><p class="c2"><span>None</span></p></td> | ||
367 | </tr> | ||
368 | <tr class="c8"> | ||
369 | <td class="c5"><p class="c2"><span>Response Headers</span></p></td> | ||
370 | <td class="c6"><p class="c2"><span>Cache-Control: no-cache</span></p></td> | ||
371 | </tr> | ||
372 | <tr class="c8"> | ||
373 | <td class="c5"><p class="c2"><span>Response Body</span></p></td> | ||
374 | <td class="c6"><p class="c2"><span>None</span></p></td> | ||
375 | </tr> | ||
376 | <tr class="c8"> | ||
377 | <td class="c5"><p class="c2"><span>Return Status Codes</span></p></td> | ||
378 | <td class="c6"><p class="c2"><span>204 “No Content” – The operation succeeded<br>404 “Not found” – | ||
379 | the source file at the indicated URI does not exist.<br>500 “Internal Server Error” – the file operation was not able to be completed.</span> | ||
380 | </p></td> | ||
381 | </tr> | ||
382 | </tbody> | ||
383 | </table> | ||
384 | <h3 class="c2"><span>Delete an existing file</span></h3> | ||
385 | <table cellpadding="0" cellspacing="0" class="c15"> | ||
386 | <tbody> | ||
387 | <tr class="c8"> | ||
388 | <td class="c5"><p class="c2"><span>URL</span></p></td> | ||
389 | <td class="c7"><p class="c2"> | ||
390 | <span>http://someURL.com/file</span><span>/<filepath>/<filename ></span></p></td> | ||
391 | </tr> | ||
392 | <tr class="c8"> | ||
393 | <td class="c5"><p class="c2"><span>Method</span></p></td> | ||
394 | <td class="c7"><p class="c2"><span>DELETE</span></p></td> | ||
395 | </tr> | ||
396 | <tr class="c8"> | ||
397 | <td class="c5"><p class="c2"><span>Request Headers</span></p></td> | ||
398 | <td class="c7"><p class="c2"><span>none</span></p></td> | ||
399 | </tr> | ||
400 | <tr class="c8"> | ||
401 | <td class="c5"><p class="c2"><span>Request Body</span></p></td> | ||
402 | <td class="c7"><p class="c2"><span>None</span></p></td> | ||
403 | </tr> | ||
404 | <tr class="c8"> | ||
405 | <td class="c5"><p class="c2"><span>Response Headers</span></p></td> | ||
406 | <td class="c7"><p class="c2"><span>Cache-Control: no-cache</span></p></td> | ||
407 | </tr> | ||
408 | <tr class="c8"> | ||
409 | <td class="c5"><p class="c2"><span>Response Body</span></p></td> | ||
410 | <td class="c7"><p class="c2"><span>None</span></p></td> | ||
411 | </tr> | ||
412 | <tr class="c8"> | ||
413 | <td class="c5"><p class="c2"><span>Return Status Codes</span></p></td> | ||
414 | <td class="c7"><p class="c2"><span>204 “No Content” – | ||
415 | File was successfully removed<br>404 “Not found” – the file at the indicated URI does not exist.<br>500 “Internal Server Error” – | ||
416 | the file was not able to be deleted.</span></p></td> | ||
417 | </tr> | ||
418 | <tr class="c8"> | ||
419 | <td class="c5"><p class="c2"><span>Notes</span></p></td> | ||
420 | <td class="c7"><p class="c2"><span>This will only delete a single file. You cannot pass wildcard characters in the path.</span> | ||
421 | </p></td> | ||
422 | </tr> | ||
423 | </tbody> | ||
424 | </table> | ||
425 | <h3 class="c2"><span>Read an existing file</span></h3> | ||
426 | <table cellpadding="0" cellspacing="0" class="c15"> | ||
427 | <tbody> | ||
428 | <tr class="c8"> | ||
429 | <td class="c5"><p class="c2"><span>URL</span></p></td> | ||
430 | <td class="c7"><p class="c2"> | ||
431 | <span>http://someURL.com/file</span><span>/<filepath>/<filename ></span></p></td> | ||
432 | </tr> | ||
433 | <tr class="c8"> | ||
434 | <td class="c5"><p class="c2"><span>Method</span></p></td> | ||
435 | <td class="c7"><p class="c2"><span>GET</span></p></td> | ||
436 | </tr> | ||
437 | <tr class="c8"> | ||
438 | <td class="c5"><p class="c2"><span>Request Headers</span></p></td> | ||
439 | <td class="c7"><p class="c2"><span class="c10">check-existence-only<br></span><span>value=true/false<br>default none<br>if true, no content is returned. The return status code indicates if the directory exists or not.</span> | ||
440 | </p> | ||
441 | |||
442 | <p class="c2"><span class="c13 c10">If-modified-since</span><span class="c13"><br>value=<ms since 1/1/1970 in GMT>. If this header is present, the server will determine if the file has been modified since the time specified. If the modified date is later than the value of “if-modified-since”, then the server will return 200. If not 304 is returned. check-existence-only is ignored when this header is specified.</span> | ||
443 | </p> | ||
444 | |||
445 | <p class="c2"><span class="c10">get-file-info</span><span><br>If specified, this will cause this api to return a JSON string containing the creation and modification times in ms since 1/1/1970, the file size in bytes and a boolean indicating if the file is read only.</span> | ||
446 | </p> | ||
447 | |||
448 | <p class="c2"><span>Example,</span></p> | ||
449 | |||
450 | <p class="c2"><span>{<br> "creationDate": "2133456525488",<br> "modifiedDate": "2133456525488",<br> "size": "2125",<br> "readOnly": "true"<br>}</span> | ||
451 | </p> | ||
452 | |||
453 | <p class="c2"><span>All three of the above headers are mutually exclusive. Only one can be specified at a time.</span> | ||
454 | </p> | ||
455 | |||
456 | <p class="c11 c2"><span></span></p></td> | ||
457 | </tr> | ||
458 | <tr class="c8"> | ||
459 | <td class="c5"><p class="c2"><span>Request Body</span></p></td> | ||
460 | <td class="c7"><p class="c2"><span>None</span></p></td> | ||
461 | </tr> | ||
462 | <tr class="c8"> | ||
463 | <td class="c5"><p class="c2"><span>Response Headers</span></p></td> | ||
464 | <td class="c7"><p class="c2"><span>Content-Type: <string></span></p> | ||
465 | |||
466 | <p class="c2"><span>Cache-Control: no-cache</span></p></td> | ||
467 | </tr> | ||
468 | <tr class="c8"> | ||
469 | <td class="c5"><p class="c2"><span>Response Body</span></p></td> | ||
470 | <td class="c7"><p class="c2"><span>Raw file data</span></p></td> | ||
471 | </tr> | ||
472 | <tr class="c8"> | ||
473 | <td class="c5"><p class="c2"><span>Return Status Codes</span></p></td> | ||
474 | <td class="c7"><p class="c2"><span>200 “OK” – The file exists and was successfully read and the contents returned with the content type. </span><span>When a time is specified with the “if-modified-since” | ||
475 | header and a file was modified after that date, a return of 200 indicates that there was a change. <br></span><span><br>204 “No Content” – | ||
476 | The file exists and no content was returned because the “check-existence-only” or </span><span>“get-file-info” </span><span>header was set to true. 304 “Not modified” | ||
477 | - returned when a </span><span>file </span><span>modification check was made and </span><span>the file was not</span><span> modified after the time specified in the “if-modified-since” | ||
478 | header.</span><span><br></span><span><br>404 “Not found” – the file at the indicated URI does not exist.</span> | ||
479 | </p></td> | ||
480 | </tr> | ||
481 | </tbody> | ||
482 | </table> | ||
483 | <p class="c2 c11"><span></span></p> | ||
484 | |||
485 | <p class="c11 c2"><span></span></p> | ||
486 | <hr style="page-break-before:always;display:none;"> | ||
487 | <h1 class="c2"><span>Directory APIs</span></h1> | ||
488 | |||
489 | <p class="c2"><span>These APIs operate on directories. The path parameter must be to a directory and not a specific file. The path parameter cannot contain wildcard characters.</span> | ||
490 | </p> | ||
491 | |||
492 | <h3 class="c2"><span>Create a new directory</span></h3> | ||
493 | <table cellpadding="0" cellspacing="0" class="c15"> | ||
494 | <tbody> | ||
495 | <tr class="c8"> | ||
496 | <td class="c4"><p class="c2"><span>URL</span></p></td> | ||
497 | <td class="c12"><p class="c2"><span>http://someURL.com/directory</span><span>/<directory path></span></p> | ||
498 | </td> | ||
499 | </tr> | ||
500 | <tr class="c8"> | ||
501 | <td class="c4"><p class="c2"><span>Method</span></p></td> | ||
502 | <td class="c12"><p class="c2"><span>POST</span></p></td> | ||
503 | </tr> | ||
504 | <tr class="c8"> | ||
505 | <td class="c4"><p class="c2"><span>Request Headers</span></p></td> | ||
506 | <td class="c12"><p class="c2"><span>none</span></p></td> | ||
507 | </tr> | ||
508 | <tr class="c8"> | ||
509 | <td class="c4"><p class="c2"><span>Request Body</span></p></td> | ||
510 | <td class="c12"><p class="c2"><span>None</span></p></td> | ||
511 | </tr> | ||
512 | <tr class="c8"> | ||
513 | <td class="c4"><p class="c2"><span>Response headers</span></p></td> | ||
514 | <td class="c12"><p class="c2"><span>Cache-Control: no-cache</span></p></td> | ||
515 | </tr> | ||
516 | <tr class="c8"> | ||
517 | <td class="c4"><p class="c2"><span>Response body</span></p></td> | ||
518 | <td class="c12"><p class="c2"><span>None</span></p></td> | ||
519 | </tr> | ||
520 | <tr class="c8"> | ||
521 | <td class="c4"><p class="c2"><span>Return Status Codes</span></p></td> | ||
522 | <td class="c12"><p class="c2"><span>201 “Created” – The directory was created<br>400 “Bad Request” – | ||
523 | the directory was not able to be created.</span></p></td> | ||
524 | </tr> | ||
525 | <tr class="c8"> | ||
526 | <td class="c4"><p class="c2"><span>Notes:</span></p></td> | ||
527 | <td class="c12"><p class="c2"><span>This will create the entire path. E.g. passing c:\foo\bar where there is no existing c:\foo directory will cause a directory “foo” | ||
528 | to be created under c:\ as well as a subdirectory named “bar” under “foo”. </span> | ||
529 | </p></td> | ||
530 | </tr> | ||
531 | </tbody> | ||
532 | </table> | ||
533 | <p class="c11 c2"><span></span></p> | ||
534 | |||
535 | <h3 class="c2"><span>Delete an existing directory</span></h3> | ||
536 | <table cellpadding="0" cellspacing="0" class="c15"> | ||
537 | <tbody> | ||
538 | <tr class="c8"> | ||
539 | <td class="c5"><p class="c2"><span>URL</span></p></td> | ||
540 | <td class="c7"><p class="c2"><span>http://someURL.com/directory</span><span>/<directory path></span></p> | ||
541 | </td> | ||
542 | </tr> | ||
543 | <tr class="c8"> | ||
544 | <td class="c5"><p class="c2"><span>Method</span></p></td> | ||
545 | <td class="c7"><p class="c2"><span>DELETE</span></p></td> | ||
546 | </tr> | ||
547 | <tr class="c8"> | ||
548 | <td class="c5"><p class="c2"><span>Request Headers</span></p></td> | ||
549 | <td class="c7"><p class="c2"><span>none</span></p></td> | ||
550 | </tr> | ||
551 | <tr class="c8"> | ||
552 | <td class="c5"><p class="c2"><span>Request Body</span></p></td> | ||
553 | <td class="c7"><p class="c2"><span>None</span></p></td> | ||
554 | </tr> | ||
555 | <tr class="c8"> | ||
556 | <td class="c5"><p class="c2"><span>Response Headers</span></p></td> | ||
557 | <td class="c7"><p class="c2"><span>Cache-Control: no-cache</span></p></td> | ||
558 | </tr> | ||
559 | <tr class="c8"> | ||
560 | <td class="c5"><p class="c2"><span>Response Body</span></p></td> | ||
561 | <td class="c7"><p class="c2"><span>None</span></p></td> | ||
562 | </tr> | ||
563 | <tr class="c8"> | ||
564 | <td class="c5"><p class="c2"><span>Return Status Codes</span></p></td> | ||
565 | <td class="c7"><p class="c2"><span>204 “No Content” – | ||
566 | The directory was successfully removed<br>404 “Not found” – the directory at the indicated URI does not exist.<br>500 “Internal Server Error” – | ||
567 | the directory was not able to be deleted.</span></p></td> | ||
568 | </tr> | ||
569 | <tr class="c8"> | ||
570 | <td class="c5"><p class="c2"><span>Notes</span></p></td> | ||
571 | <td class="c7"><p class="c11 c2"><span></span></p></td> | ||
572 | </tr> | ||
573 | </tbody> | ||
574 | </table> | ||
575 | <p class="c11 c2"><span></span></p> | ||
576 | |||
577 | <h3 class="c2"><span>List the contents of an existing directory</span></h3> | ||
578 | <table cellpadding="0" cellspacing="0" class="c15"> | ||
579 | <tbody> | ||
580 | <tr class="c8"> | ||
581 | <td class="c5"><p class="c2"><span>URL</span></p></td> | ||
582 | <td class="c7"><p class="c2"><span>http://someURL.com/directory</span><span>/<directory path></span></p> | ||
583 | </td> | ||
584 | </tr> | ||
585 | <tr class="c8"> | ||
586 | <td class="c5"><p class="c2"><span>Method</span></p></td> | ||
587 | <td class="c7"><p class="c2"><span>GET</span></p></td> | ||
588 | </tr> | ||
589 | <tr class="c8"> | ||
590 | <td class="c5"><p class="c2"><span>Request Headers</span></p></td> | ||
591 | <td class="c7"><p class="c2"><span class="c3">Required</span></p> | ||
592 | |||
593 | <p class="c2"><span class="c10">recursive</span><span><br>value=true/false<br>default=false<br>if set to true this call will get the contents of every sub-directory recursively, except if return-type is set to “files”, then only the files in the top level directory are returned.<br><br>file-filters<br>specifies the filters to use for files that are returned. Only those matching one of the filters listed will be returned. The default is an empty string meaning all files are returned. Do not include * as an filter. To not filter by extension either do not set this header or pass an empty string.<br>value=<semi-colon delimited filter list><br>e.g. “xml;html”<br><br>return-type<br>value=”directories”, “files”, “all”<br>default=”all”<br>“directories” – | ||
594 | only subdirectories of the URI will be returned<br>“files” – only files within the directory will be returned<br>“all” – | ||
595 | both subdirectories and files will be returned<br><br></span><span class="c10">check-existence-only<br></span><span>value=true/false<br>default false<br>if true, no content is returned. The return status code indicates if the directory exists or not. “recursive” | ||
596 | and “return-type” are ignored if this header is set to true.</span></p> | ||
597 | |||
598 | <p class="c2"><span class="c13 c10">If-modified-since</span><span class="c13"><br>value=<ms since 1/1/1970 in GMT>. If this header is present, the server will compare the modification times of the folder AND its contents (recursively if “recursive” | ||
599 | is true) against the specified date. If any folder/file has a modified date later than the value of “if-modified-since”, then the server will return 200. If no file/folder was modified after that time then 304 is returned. check-existence-only is ignored when this header is specified.</span> | ||
600 | </p> | ||
601 | |||
602 | <p class="c2"><span>NOTE: If the path is empty, then all parameters are ignored and the API returns all top level disks and or folders available to the user.</span> | ||
603 | </p> | ||
604 | |||
605 | <p class="c2"><span>TBD for cloud: may need to include credentials and user account info</span></p></td> | ||
606 | </tr> | ||
607 | <tr class="c8"> | ||
608 | <td class="c5"><p class="c2"><span>Request Body</span></p></td> | ||
609 | <td class="c7"><p class="c2"><span>None</span></p></td> | ||
610 | </tr> | ||
611 | <tr class="c8"> | ||
612 | <td class="c5"><p class="c2"><span>Response Headers</span></p></td> | ||
613 | <td class="c7"><p class="c2"><span>Content-Type: </span><span class="c18">application/json</span></p> | ||
614 | |||
615 | <p class="c2"><span>Cache-Control: no-cache</span></p></td> | ||
616 | </tr> | ||
617 | <tr class="c8"> | ||
618 | <td class="c5"><p class="c2"><span>Response Body</span></p></td> | ||
619 | <td class="c7"><p class="c0"><span>JSON listing the directory contents. </span></p> | ||
620 | |||
621 | <p class="c0"><span>Example:</span></p> | ||
622 | |||
623 | <p class="c0"><span>the json below represents the response for a listing of the “c:/my documents” | ||
624 | directory</span></p> | ||
625 | |||
626 | <p class="c0"><span>The type property of the object can be used to differentiate between files and directories. Both files and directories also contain a name, uri property</span><span> as well as a creationDate and modifiedDate. The dates are all in milliseconds since UNIX epoch. </span><span>Directories also contain a children property. If the children property is an empty array it means that the directory has no contents. If the children property is defined but null, that means the directory does have content but that content has not yet been retrieved. Another XHR must be called to obtain its contents. If the children property is an array with a size > 0, then it contains the contents of the directory.</span> | ||
627 | </p> | ||
628 | |||
629 | <p class="c0 c11"><span></span></p> | ||
630 | |||
631 | <p class="c0"><span>{</span></p> | ||
632 | |||
633 | <p class="c0"><span> "type": “directory”,</span></p> | ||
634 | |||
635 | <p class="c0"><span> "name": "my documents",</span></p> | ||
636 | |||
637 | <p class="c0"><span> "uri": "c:/my documents/",</span></p> | ||
638 | |||
639 | <p class="c0"><span> "children":[</span></p> | ||
640 | |||
641 | <p class="c0"><span> {</span></p> | ||
642 | |||
643 | <p class="c0"><span> "type": “directory”,</span></p> | ||
644 | |||
645 | <p class="c0"><span> "name":"subDirectory",</span></p> | ||
646 | |||
647 | <p class="c0"><span> "uri":"c:/my documents/subDirectory",</span> | ||
648 | </p> | ||
649 | |||
650 | <p class="c0"><span> “creationDate”:”2133456525488”,</span> | ||
651 | </p> | ||
652 | |||
653 | <p class="c0"><span> “modifiedDate”:”2133456525488”,<br> “size”:”21335”,<br> “writable”:”true”,</span> | ||
654 | </p> | ||
655 | |||
656 | <p class="c0"><span> "children":[</span></p> | ||
657 | |||
658 | <p class="c0"><span> {</span></p> | ||
659 | |||
660 | <p class="c0 c9"><span>"type": “directory”</span></p> | ||
661 | |||
662 | <p class="c0"><span> "name":"anotherDir",</span> | ||
663 | </p> | ||
664 | |||
665 | <p class="c0"><span> "uri":"c:/my documents/subDirectory/anotherDir",</span> | ||
666 | </p> | ||
667 | |||
668 | <p class="c0"><span> “size”:”33225”,<br> “writable”:”true”,</span> | ||
669 | </p> | ||
670 | |||
671 | <p class="c0"><span> "children":null</span> | ||
672 | </p> | ||
673 | |||
674 | <p class="c0"><span> },</span></p> | ||
675 | |||
676 | <p class="c0"><span> {</span></p> | ||
677 | |||
678 | <p class="c0"><span> "type": “directory”,</span> | ||
679 | </p> | ||
680 | |||
681 | <p class="c0 c9"><span>"name":"anEmptySubdirectory",</span></p> | ||
682 | |||
683 | <p class="c0"><span> "uri":"c:/my documents/subDirectory/anEmptySubdirectory"</span> | ||
684 | </p> | ||
685 | |||
686 | <p class="c0"><span> “creationDate”:”2133456525488”,</span> | ||
687 | </p> | ||
688 | |||
689 | <p class="c0"><span> “modifiedDate”:”2133456525488”,</span> | ||
690 | </p> | ||
691 | |||
692 | <p class="c0"><span> “size”:”2125”,<br> “writable”:”true”,</span> | ||
693 | </p> | ||
694 | |||
695 | <p class="c0"><span> },</span></p> | ||
696 | |||
697 | <p class="c0"><span> {</span></p> | ||
698 | |||
699 | <p class="c0"><span> "type": “file”,</span> | ||
700 | </p> | ||
701 | |||
702 | <p class="c0 c9"><span>"name":"aFile.txt",</span></p> | ||
703 | |||
704 | <p class="c0"><span> "uri":"c:/my documents/subDirectory/aFile.txt",</span> | ||
705 | </p> | ||
706 | |||
707 | <p class="c0"><span> “creationDate”:”2133456525488”,</span> | ||
708 | </p> | ||
709 | |||
710 | <p class="c0"><span> “modifiedDate”:”2133456525488”,</span> | ||
711 | </p> | ||
712 | |||
713 | <p class="c0"><span> “size”:”2125”,<br> “writable”:”true”,</span> | ||
714 | </p> | ||
715 | |||
716 | <p class="c0"><span> }</span></p> | ||
717 | |||
718 | <p class="c0"><span> ]</span></p> | ||
719 | |||
720 | <p class="c0"><span> },</span></p> | ||
721 | |||
722 | <p class="c0"><span> {</span></p> | ||
723 | |||
724 | <p class="c0"><span> “type”:"file",</span></p> | ||
725 | |||
726 | <p class="c0"><span> "name":"someFile.html",</span></p> | ||
727 | |||
728 | <p class="c0"><span> "uri":"c:/my documents/someFile.html",</span> | ||
729 | </p> | ||
730 | |||
731 | <p class="c0"><span> “creationDate”:”2133456525488”,</span> | ||
732 | </p> | ||
733 | |||
734 | <p class="c0"><span> “modifiedDate”:”2133456525488”,</span> | ||
735 | </p> | ||
736 | |||
737 | <p class="c0"><span> “size”:”6652”,<br> “writable”:”false”,</span> | ||
738 | </p> | ||
739 | |||
740 | <p class="c0"><span> }</span></p> | ||
741 | |||
742 | <p class="c0"><span> ]</span></p> | ||
743 | |||
744 | <p class="c0"><span>}</span></p></td> | ||
745 | </tr> | ||
746 | <tr class="c8"> | ||
747 | <td class="c5"><p class="c2"><span>Return Status Codes</span></p></td> | ||
748 | <td class="c7"><p class="c2"><span>200 “OK” – The directory exists and its contents were successfully read and the returned in the response body. </span><span>When a time is specified with the “if-modified-since” | ||
749 | header and a file/folder was modified after that date, a return of 200 indicates that there was a change.</span><span><br>204 “No Content” – | ||
750 | The directory exists and no content was returned because the “check-existence-only” header was set to true</span><span><br>304 “Not modified” | ||
751 | - returned when a folder modification check was made and no contents were modified after the time specified in the “if-modified-since” | ||
752 | header.</span><span><br>404 “Not found” – the directory at the indicated URI does not exist.</span><span><br>413 “Request entity too large” | ||
753 | - the request timed out. This can happen if the request is taking too long to process when doing a recursive query.</span> | ||
754 | </p></td> | ||
755 | </tr> | ||
756 | </tbody> | ||
757 | </table> | ||
758 | <h3 class="c2"><span class="c16"><br></span><span>Copy, Move of an existing directory </span></h3> | ||
759 | <table cellpadding="0" cellspacing="0" class="c15"> | ||
760 | <tbody> | ||
761 | <tr class="c8"> | ||
762 | <td class="c5"><p class="c2"><span>URL</span></p></td> | ||
763 | <td class="c6"><p class="c2"><span>http://someURL.com/directory</span><span>/<directory path></span></p> | ||
764 | </td> | ||
765 | </tr> | ||
766 | <tr class="c8"> | ||
767 | <td class="c5"><p class="c2"><span>Method</span></p></td> | ||
768 | <td class="c6"><p class="c2"><span>PUT</span></p></td> | ||
769 | </tr> | ||
770 | <tr class="c8"> | ||
771 | <td class="c5"><p class="c2"><span>Request Headers</span></p></td> | ||
772 | <td class="c6"><p class="c2"><span class="c3">Required</span></p> | ||
773 | |||
774 | <p class="c2"><span class="c10">sourceURI</span><span><br>value= <source directory path in same format as in the URL></span> | ||
775 | </p> | ||
776 | |||
777 | <p class="c2"><span class="c10">operation<br></span><span>value=”copy” or “move”<br></span> | ||
778 | </p> | ||
779 | |||
780 | <p class="c2"><span>NOTE: the destination directory must not exist.</span></p> | ||
781 | |||
782 | <p class="c2"><span>TBD for cloud: may need to include credentials and user account info</span></p></td> | ||
783 | </tr> | ||
784 | <tr class="c8"> | ||
785 | <td class="c5"><p class="c2"><span>Request Body</span></p></td> | ||
786 | <td class="c6"><p class="c2"><span>None</span></p></td> | ||
787 | </tr> | ||
788 | <tr class="c8"> | ||
789 | <td class="c5"><p class="c2"><span>Response Headers</span></p></td> | ||
790 | <td class="c6"><p class="c2"><span>Cache-Control: no-cache</span></p></td> | ||
791 | </tr> | ||
792 | <tr class="c8"> | ||
793 | <td class="c5"><p class="c2"><span>Response Body</span></p></td> | ||
794 | <td class="c6"><p class="c2"><span>None</span></p></td> | ||
795 | </tr> | ||
796 | <tr class="c8"> | ||
797 | <td class="c5"><p class="c2"><span>Return Status Codes</span></p></td> | ||
798 | <td class="c6"><p class="c2"><span>204 “No Content” – The operation succeeded<br>404 “Not found” – | ||
799 | the source file at the indicated URI does not exist.<br>400-“Bad Request” – if the operation value is invalid or if the destination directory <br>500 “Internal Server Error” – | ||
800 | the file operation was not able to be completed.</span></p></td> | ||
801 | </tr> | ||
802 | </tbody> | ||
803 | </table> | ||
804 | |||
805 | <h1 class="c2"><span>Web API</span></h1> | ||
806 | <p class="c2">This API is used to request file data from a URL.</p> | ||
807 | <h3 class="c2">Get text or binary data from a URL</h3> | ||
808 | <table cellpadding="0" cellspacing="0" class="c15"> | ||
809 | <tbody> | ||
810 | <tr class="c8"> | ||
811 | <td class="c5"><p class="c2"><span>URL</span></p></td> | ||
812 | <td class="c6"><p class="c2">http://someURL.com/web?url=http://foo.com/bar.txt</p> | ||
813 | </td> | ||
814 | </tr> | ||
815 | <tr class="c8"> | ||
816 | <td class="c5"><p class="c2"><span>Method</span></p></td> | ||
817 | <td class="c6"><p class="c2"><span>GET</span></p></td> | ||
818 | </tr> | ||
819 | <tr class="c8"> | ||
820 | <td class="c5"><p class="c2"><span>Request Headers</span></p></td> | ||
821 | <td class="c6"><p class="c2"><span class="c3">Required</span></p> | ||
822 | <p class="c2"><span class="c10">return-type<br></span><span>value=”text” or “binary”</span><br>default=“text“</p> | ||
823 | </tr> | ||
824 | <tr class="c8"> | ||
825 | <td class="c5"><p class="c2"><span>Request Body</span></p></td> | ||
826 | <td class="c6"><p class="c2"><span>None</span></p></td> | ||
827 | </tr> | ||
828 | <tr class="c8"> | ||
829 | <td class="c5"><p class="c2"><span>Response Headers</span></p></td> | ||
830 | <td class="c6"><p class="c2"><span>Cache-Control: no-cache</span></p></td> | ||
831 | </tr> | ||
832 | <tr class="c8"> | ||
833 | <td class="c5"><p class="c2"><span>Response Body</span></p></td> | ||
834 | <td class="c6"><p class="c2"><span>None</span></p></td> | ||
835 | </tr> | ||
836 | <tr class="c8"> | ||
837 | <td class="c5"><p class="c2"><span>Return Status Codes</span></p></td> | ||
838 | <td class="c6"><p class="c2"><span>200 “OK” – The operation succeeded<br>404 “Not found” – | ||
839 | the source file at the indicated URI does not exist.<br>501-“Not Implemented” – if any method other than GET is used</span></p></td> | ||
840 | </tr> | ||
841 | </tbody> | ||
842 | </table> | ||
843 | |||
844 | <h1 class="c2">Cloud Status API</h1> | ||
845 | <p class="c2">This API is used to request cloud status information.</p> | ||
846 | <h3 class="c2">Get the cloud status JSON</h3> | ||
847 | <table cellpadding="0" cellspacing="0" class="c15"> | ||
848 | <tbody> | ||
849 | <tr class="c8"> | ||
850 | <td class="c5"><p class="c2">URL</p></td> | ||
851 | <td class="c6"><p class="c2">http://someURL.com/cloudstatus</p> | ||
852 | </td> | ||
853 | </tr> | ||
854 | <tr class="c8"> | ||
855 | <td class="c5"><p class="c2">Method</p></td> | ||
856 | <td class="c6"><p class="c2">GET</p></td> | ||
857 | </tr> | ||
858 | <tr class="c8"> | ||
859 | <td class="c5"><p class="c2">Request Headers</p></td> | ||
860 | <td class="c6"><p class="c2">None</p></td> | ||
861 | </tr> | ||
862 | <tr class="c8"> | ||
863 | <td class="c5"><p class="c2">Request Body</p></td> | ||
864 | <td class="c6"><p class="c2">None</p></td> | ||
865 | </tr> | ||
866 | <tr class="c8"> | ||
867 | <td class="c5"><p class="c2">Response Headers</p></td> | ||
868 | <td class="c6"><p class="c2">Cache-Control: no-cache</p></td> | ||
869 | </tr> | ||
870 | <tr class="c8"> | ||
871 | <td class="c5"><p class="c2">Response Body</p></td> | ||
872 | <td class="c6"><p class="c2">JSON string containg the cloud status</p></td> | ||
873 | </tr> | ||
874 | <tr class="c8"> | ||
875 | <td class="c5"><p class="c2">Return Status Codes</p></td> | ||
876 | <td class="c6"><p class="c2">200 “OK” – The operation succeeded</p></td> | ||
877 | </tr> | ||
878 | </tbody> | ||
879 | </table> | ||
880 | </body> | ||
881 | </html> \ No newline at end of file | ||
diff --git a/src/ninjacloud.go b/src/ninjacloud.go new file mode 100644 index 0000000..2d3c2f0 --- /dev/null +++ b/src/ninjacloud.go | |||
@@ -0,0 +1,145 @@ | |||
1 | package main | ||
2 | |||
3 | import ( | ||
4 | "flag" | ||
5 | "log" | ||
6 | "net/http" | ||
7 | "path" | ||
8 | //"io/ioutil" | ||
9 | //"os" | ||
10 | ) | ||
11 | |||
12 | const APP_NAME = "Ninja Go Local Cloud" | ||
13 | const APP_VERSION = "0.1 Draft" | ||
14 | |||
15 | var versionFlag bool | ||
16 | var interfaceFlag string | ||
17 | var portFlag string | ||
18 | var rootFlag string | ||
19 | |||
20 | const filePath = "/file/" | ||
21 | const dirPath = "/directory/" | ||
22 | const webPath = "/web?url=" | ||
23 | const statusPath = "/cloudstatus" | ||
24 | |||
25 | const filePathLen = len(filePath) | ||
26 | const dirPathLen = len(dirPath) | ||
27 | const webPathLen = len(webPath) | ||
28 | const statusPathLen = len(statusPath) | ||
29 | |||
30 | //////// FILESYSTEM | ||
31 | |||
32 | //// Files | ||
33 | |||
34 | func writeFile() { | ||
35 | } | ||
36 | |||
37 | func readFile() { | ||
38 | } | ||
39 | |||
40 | func removeFile() { | ||
41 | } | ||
42 | |||
43 | func copyFile() { | ||
44 | } | ||
45 | |||
46 | //// Dirs | ||
47 | |||
48 | func createDir() { | ||
49 | } | ||
50 | |||
51 | func removeDir() { | ||
52 | } | ||
53 | |||
54 | func listDir() { | ||
55 | } | ||
56 | |||
57 | func copyDir() { | ||
58 | } | ||
59 | |||
60 | //////// REQUEST HANDLERS | ||
61 | |||
62 | //// File APIs | ||
63 | |||
64 | func fileHandler(w http.ResponseWriter, r *http.Request) { | ||
65 | p := r.URL.Path[filePathLen:] | ||
66 | path.Clean(p) | ||
67 | |||
68 | switch r.Method { | ||
69 | case "POST": | ||
70 | // Create a new file | ||
71 | case "PUT": | ||
72 | if r.Header.Get("sourceURI") == "" { | ||
73 | // Update an existing file (save over existing file) | ||
74 | } else { | ||
75 | // Copy, Move of an existing file | ||
76 | } | ||
77 | case "DELETE": | ||
78 | // Delete an existing file | ||
79 | case "GET": | ||
80 | // Read an existing file | ||
81 | } | ||
82 | |||
83 | } | ||
84 | |||
85 | //// Directory APIs | ||
86 | |||
87 | func dirHandler(w http.ResponseWriter, r *http.Request) { | ||
88 | p := r.URL.Path[dirPathLen:] | ||
89 | path.Clean(p) | ||
90 | |||
91 | switch r.Method { | ||
92 | case "POST": | ||
93 | // Create a new directory | ||
94 | case "DELETE": | ||
95 | // Delete an existing directory | ||
96 | case "GET": | ||
97 | // List the contents of an existing directory | ||
98 | case "PUT": | ||
99 | // Copy, Move of an existing directory | ||
100 | } | ||
101 | |||
102 | } | ||
103 | |||
104 | //// Web API | ||
105 | |||
106 | // Get text or binary data from a URL | ||
107 | func getDataHandler(w http.ResponseWriter, r *http.Request) { | ||
108 | } | ||
109 | |||
110 | //// Cloud Status API | ||
111 | |||
112 | // Get the cloud status JSON | ||
113 | func getStatusHandler(w http.ResponseWriter, r *http.Request) { | ||
114 | } | ||
115 | |||
116 | //////// INIT and MAIN | ||
117 | |||
118 | func init() { | ||
119 | flag.BoolVar(&versionFlag, "v", false, "Print the version number.") | ||
120 | flag.StringVar(&interfaceFlag, "i", "localhost", "Listening interface.") | ||
121 | flag.StringVar(&portFlag, "p", "58080", "Listening port.") | ||
122 | flag.StringVar(&rootFlag, "r", ".", "Root directory.") | ||
123 | } | ||
124 | |||
125 | func main() { | ||
126 | flag.Parse() | ||
127 | |||
128 | if versionFlag { | ||
129 | log.Println("Version:", APP_VERSION) | ||
130 | return | ||
131 | } | ||
132 | |||
133 | log.Println("Starting " + APP_NAME + " " + APP_VERSION + " on " + interfaceFlag + ":" + portFlag + " in " + rootFlag) | ||
134 | |||
135 | http.HandleFunc(filePath, fileHandler) | ||
136 | http.HandleFunc(dirPath, dirHandler) | ||
137 | http.HandleFunc(webPath, getDataHandler) | ||
138 | http.HandleFunc(statusPath, getStatusHandler) | ||
139 | |||
140 | err := http.ListenAndServe(interfaceFlag+":"+portFlag, nil) | ||
141 | if err != nil { | ||
142 | log.Println(err) | ||
143 | return | ||
144 | } | ||
145 | } | ||