summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ninjacloud.go145
1 files changed, 145 insertions, 0 deletions
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 @@
1package main
2
3import (
4 "flag"
5 "log"
6 "net/http"
7 "path"
8 //"io/ioutil"
9 //"os"
10)
11
12const APP_NAME = "Ninja Go Local Cloud"
13const APP_VERSION = "0.1 Draft"
14
15var versionFlag bool
16var interfaceFlag string
17var portFlag string
18var rootFlag string
19
20const filePath = "/file/"
21const dirPath = "/directory/"
22const webPath = "/web?url="
23const statusPath = "/cloudstatus"
24
25const filePathLen = len(filePath)
26const dirPathLen = len(dirPath)
27const webPathLen = len(webPath)
28const statusPathLen = len(statusPath)
29
30//////// FILESYSTEM
31
32//// Files
33
34func writeFile() {
35}
36
37func readFile() {
38}
39
40func removeFile() {
41}
42
43func copyFile() {
44}
45
46//// Dirs
47
48func createDir() {
49}
50
51func removeDir() {
52}
53
54func listDir() {
55}
56
57func copyDir() {
58}
59
60//////// REQUEST HANDLERS
61
62//// File APIs
63
64func 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
87func 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
107func getDataHandler(w http.ResponseWriter, r *http.Request) {
108}
109
110//// Cloud Status API
111
112// Get the cloud status JSON
113func getStatusHandler(w http.ResponseWriter, r *http.Request) {
114}
115
116//////// INIT and MAIN
117
118func 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
125func 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}