From c5a9744b87354f67e219ee0069180a94ed27c3ee Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sat, 8 Sep 2012 14:02:56 +0200 Subject: First draft: program structure. --- src/ninjacloud.go | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 src/ninjacloud.go (limited to 'src') 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 @@ +package main + +import ( + "flag" + "log" + "net/http" + "path" + //"io/ioutil" + //"os" +) + +const APP_NAME = "Ninja Go Local Cloud" +const APP_VERSION = "0.1 Draft" + +var versionFlag bool +var interfaceFlag string +var portFlag string +var rootFlag string + +const filePath = "/file/" +const dirPath = "/directory/" +const webPath = "/web?url=" +const statusPath = "/cloudstatus" + +const filePathLen = len(filePath) +const dirPathLen = len(dirPath) +const webPathLen = len(webPath) +const statusPathLen = len(statusPath) + +//////// FILESYSTEM + +//// Files + +func writeFile() { +} + +func readFile() { +} + +func removeFile() { +} + +func copyFile() { +} + +//// Dirs + +func createDir() { +} + +func removeDir() { +} + +func listDir() { +} + +func copyDir() { +} + +//////// REQUEST HANDLERS + +//// File APIs + +func fileHandler(w http.ResponseWriter, r *http.Request) { + p := r.URL.Path[filePathLen:] + path.Clean(p) + + switch r.Method { + case "POST": + // Create a new file + case "PUT": + if r.Header.Get("sourceURI") == "" { + // Update an existing file (save over existing file) + } else { + // Copy, Move of an existing file + } + case "DELETE": + // Delete an existing file + case "GET": + // Read an existing file + } + +} + +//// Directory APIs + +func dirHandler(w http.ResponseWriter, r *http.Request) { + p := r.URL.Path[dirPathLen:] + path.Clean(p) + + switch r.Method { + case "POST": + // Create a new directory + case "DELETE": + // Delete an existing directory + case "GET": + // List the contents of an existing directory + case "PUT": + // Copy, Move of an existing directory + } + +} + +//// Web API + +// Get text or binary data from a URL +func getDataHandler(w http.ResponseWriter, r *http.Request) { +} + +//// Cloud Status API + +// Get the cloud status JSON +func getStatusHandler(w http.ResponseWriter, r *http.Request) { +} + +//////// INIT and MAIN + +func init() { + flag.BoolVar(&versionFlag, "v", false, "Print the version number.") + flag.StringVar(&interfaceFlag, "i", "localhost", "Listening interface.") + flag.StringVar(&portFlag, "p", "58080", "Listening port.") + flag.StringVar(&rootFlag, "r", ".", "Root directory.") +} + +func main() { + flag.Parse() + + if versionFlag { + log.Println("Version:", APP_VERSION) + return + } + + log.Println("Starting " + APP_NAME + " " + APP_VERSION + " on " + interfaceFlag + ":" + portFlag + " in " + rootFlag) + + http.HandleFunc(filePath, fileHandler) + http.HandleFunc(dirPath, dirHandler) + http.HandleFunc(webPath, getDataHandler) + http.HandleFunc(statusPath, getStatusHandler) + + err := http.ListenAndServe(interfaceFlag+":"+portFlag, nil) + if err != nil { + log.Println(err) + return + } +} -- cgit v1.2.3