summaryrefslogtreecommitdiff
path: root/cli/imgup/main.go
diff options
context:
space:
mode:
authorHorus32015-04-21 05:57:21 +0200
committerHorus32015-04-21 05:57:21 +0200
commit7e4ccc40be46366fd8c0550aca1bfb6e73c3b5c6 (patch)
tree659e0206d73607dbe2cdb75ab871e078d06d37ad /cli/imgup/main.go
parentc92ed3c93c379368f615809aa599426890bf2057 (diff)
downloadmandible-7e4ccc40be46366fd8c0550aca1bfb6e73c3b5c6.tar.gz
Add cli program.
Diffstat (limited to 'cli/imgup/main.go')
-rw-r--r--cli/imgup/main.go65
1 files changed, 65 insertions, 0 deletions
diff --git a/cli/imgup/main.go b/cli/imgup/main.go
new file mode 100644
index 0000000..660d07c
--- /dev/null
+++ b/cli/imgup/main.go
@@ -0,0 +1,65 @@
+package main
+
+import (
+ "encoding/json"
+ "fmt"
+ "os"
+)
+
+/* TODO: Make this configurable. */
+
+//var apiHost = "http://127.0.0.1:8080"
+var apiHost = "http://images.iamfabulous.de"
+var apiUrl = apiHost + "/api/v1/"
+
+func main() {
+ if len(os.Args) == 1 {
+ pstat, _ := os.Stat(os.Args[0])
+ programName := pstat.Name()
+
+ fmt.Println("Usage: " + os.Args[0] + " [FILE] [URL]")
+ fmt.Print("\n")
+ fmt.Println(programName + " uploads an image to " + apiHost + ".")
+ //fmt.Println("FILE should be a path to a image file.")
+ os.Exit(0)
+ }
+
+ for k, v := range os.Args {
+ if k > 0 {
+ if stat, err := os.Stat(v); err != nil {
+ err := urlUpload(apiUrl+"url", v, v)
+ if err != nil {
+ fmt.Println("There is an error. Are you sure the url is correct?")
+ fmt.Printf("\n")
+ fmt.Println("Technical information: ")
+ fmt.Println(" "+err.Error(), "\n")
+ }
+ } else {
+ err := fileUpload(apiUrl+"file", v, stat.Name())
+ if err != nil {
+ fmt.Println("There is an error. Are you sure the url is correct?")
+ fmt.Printf("\n")
+ fmt.Println("Technical information: ")
+ fmt.Println(" "+err.Error(), "\n")
+ }
+ }
+ }
+ }
+ fmt.Println("Have a nice day!")
+}
+
+func printResponse(res []byte, name string) {
+ r := response{}
+ json.Unmarshal(res, &r)
+ if r.Success {
+ fmt.Println("Your image (" + name + ") was uploaded!\n")
+ fmt.Println("Follow this link: \n" + " " + r.Data.Link)
+ fmt.Print("\n")
+
+ } else {
+ fmt.Println("There was an error during upload. (" + name + ")")
+ fmt.Print("\n")
+ fmt.Println("The website says: \n " + r.Data.Error)
+ fmt.Print("\n")
+ }
+}