From 5489b3d59baf04d067e15055fed6e0fed86876f3 Mon Sep 17 00:00:00 2001 From: deranjer Date: Fri, 15 Sep 2017 16:49:20 -0400 Subject: [PATCH] Initial commit, just the basic webui layout and basic golang backend with websocket communication tested. --- .idea/misc.xml | 4 + .idea/modules.xml | 8 + .idea/torrent-project.iml | 9 + .idea/vcs.xml | 6 + main.go | 72 ++++++++ projectFilesBackup/.idea/workspace.xml | 172 ++++++++++++++++++ public/static/css/gridbase.css | 120 ++++++++++++ public/static/images/iconActiveTorrents.png | Bin 0 -> 546 bytes public/static/images/iconAddTorrent.png | Bin 0 -> 913 bytes public/static/images/iconAddTorrentLink.png | Bin 0 -> 527 bytes public/static/images/iconDelete.png | Bin 0 -> 794 bytes public/static/images/iconDownList.png | Bin 0 -> 753 bytes public/static/images/iconDownload.png | Bin 0 -> 506 bytes public/static/images/iconInactiveTorrents.png | Bin 0 -> 787 bytes public/static/images/iconPause.png | Bin 0 -> 251 bytes public/static/images/iconRSS.png | Bin 0 -> 850 bytes public/static/images/iconScrollDown.png | Bin 0 -> 565 bytes public/static/images/iconScrollUp.png | Bin 0 -> 579 bytes public/static/images/iconSettings.png | Bin 0 -> 1450 bytes public/static/images/iconStart.png | Bin 0 -> 524 bytes public/static/images/iconStop.png | Bin 0 -> 219 bytes public/static/images/iconTorrent.png | Bin 0 -> 539 bytes public/static/images/iconUpList.png | Bin 0 -> 728 bytes public/static/images/iconUpload.png | Bin 0 -> 470 bytes public/static/images/testicon.png | Bin 0 -> 1014 bytes templates/home.tmpl | 161 ++++++++++++++++ 26 files changed, 552 insertions(+) create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/torrent-project.iml create mode 100644 .idea/vcs.xml create mode 100644 main.go create mode 100644 projectFilesBackup/.idea/workspace.xml create mode 100644 public/static/css/gridbase.css create mode 100644 public/static/images/iconActiveTorrents.png create mode 100644 public/static/images/iconAddTorrent.png create mode 100644 public/static/images/iconAddTorrentLink.png create mode 100644 public/static/images/iconDelete.png create mode 100644 public/static/images/iconDownList.png create mode 100644 public/static/images/iconDownload.png create mode 100644 public/static/images/iconInactiveTorrents.png create mode 100644 public/static/images/iconPause.png create mode 100644 public/static/images/iconRSS.png create mode 100644 public/static/images/iconScrollDown.png create mode 100644 public/static/images/iconScrollUp.png create mode 100644 public/static/images/iconSettings.png create mode 100644 public/static/images/iconStart.png create mode 100644 public/static/images/iconStop.png create mode 100644 public/static/images/iconTorrent.png create mode 100644 public/static/images/iconUpList.png create mode 100644 public/static/images/iconUpload.png create mode 100644 public/static/images/testicon.png create mode 100644 templates/home.tmpl diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..da035de2 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..cee7cf51 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/torrent-project.iml b/.idea/torrent-project.iml new file mode 100644 index 00000000..5e764c4f --- /dev/null +++ b/.idea/torrent-project.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/main.go b/main.go new file mode 100644 index 00000000..5cec422c --- /dev/null +++ b/main.go @@ -0,0 +1,72 @@ +package main + +import ( + "flag" + "fmt" + "github.com/gorilla/mux" + "github.com/gorilla/websocket" + "html/template" + "log" + "net/http" + "os" + "time" +) + +var ( + httpAddr = flag.String("addr", ":8000", "Http server address") + baseTmpl string = "templates/base.tmpl" + + APP_ID = os.Getenv("APP_ID") + APP_SECRET = os.Getenv("APP_SECRET") +) + +var upgrader = websocket.Upgrader{ + ReadBufferSize: 1024, + WriteBufferSize: 1024, +} + +func serveHome(w http.ResponseWriter, r *http.Request) { + s1, _ := template.ParseFiles("templates/home.tmpl") + s1.ExecuteTemplate(w, "base", map[string]string{"APP_ID": APP_ID}) +} + +func main() { + + r := mux.NewRouter() + + r.HandleFunc("/", serveHome) + http.Handle("/static/", http.FileServer(http.Dir("public"))) + http.Handle("/", r) + http.HandleFunc("/websocket", func(w http.ResponseWriter, r *http.Request) { + conn, err := upgrader.Upgrade(w, r, nil) + if err != nil { + log.Println(err) + return + } + for { + msgType, msg, err := conn.ReadMessage() + if err != nil { + fmt.Println(err) + return + } + if string(msg) == "ping" { + fmt.Println("ping") + time.Sleep(2 * time.Second) + err = conn.WriteMessage(msgType, []byte("pong")) + if err != nil { + fmt.Println(err) + return + } + } else { + conn.Close() + fmt.Println(string(msg)) + return + } + } + }) + if err := http.ListenAndServe(*httpAddr, nil); err != nil { + log.Fatalf("Error listening, %v", err) + } + + // +} diff --git a/projectFilesBackup/.idea/workspace.xml b/projectFilesBackup/.idea/workspace.xml new file mode 100644 index 00000000..866e12c0 --- /dev/null +++ b/projectFilesBackup/.idea/workspace.xml @@ -0,0 +1,172 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + +