From 0ecc0965aa2085a0adb56ed7bea4e64663409d8d Mon Sep 17 00:00:00 2001 From: ljamt Date: Mon, 2 Jul 2018 18:05:42 +0200 Subject: [PATCH 01/20] #1 simple web server using cgo for requesting cse-core hello_world() --- .gitignore | 2 ++ README.md | 4 ++++ cse.go | 19 +++++++++++++++++++ layout.html | 8 ++++++++ main.go | 5 +++++ server.go | 35 +++++++++++++++++++++++++++++++++++ 6 files changed, 73 insertions(+) create mode 100644 cse.go create mode 100644 layout.html create mode 100644 main.go create mode 100644 server.go diff --git a/.gitignore b/.gitignore index f1c181e..97cca67 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ # Output of the go coverage tool, specifically when used with LiteIDE *.out + +.idea diff --git a/README.md b/README.md index 1ecd3b9..f7539aa 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,6 @@ # cse-server-go playground for testing go as an alternative for the cse-server + +*Note* csecorec.dll and csecorecpp.dll must be manually copied into root folder + + diff --git a/cse.go b/cse.go new file mode 100644 index 0000000..d4ece5d --- /dev/null +++ b/cse.go @@ -0,0 +1,19 @@ +package main + +/* + #cgo CFLAGS: -I../install/include + #cgo LDFLAGS: -L../install/bin -lcsecorec + #include "../install/include/cse.h" + + int hello_world() { + char buf1[20]; + int ret = cse_hello_world(buf1, 20); + return ret; + } +*/ +import "C" + +func cse_hello() (number int) { + number = int(C.hello_world()) + return +} \ No newline at end of file diff --git a/layout.html b/layout.html new file mode 100644 index 0000000..9fdf3cc --- /dev/null +++ b/layout.html @@ -0,0 +1,8 @@ +

{{.PageTitle}}

+
+ +
+
+ +
+

{{.CseAnswer}}

\ No newline at end of file diff --git a/main.go b/main.go new file mode 100644 index 0000000..272f2c8 --- /dev/null +++ b/main.go @@ -0,0 +1,5 @@ +package main + +func main() { + Server() +} \ No newline at end of file diff --git a/server.go b/server.go new file mode 100644 index 0000000..695d661 --- /dev/null +++ b/server.go @@ -0,0 +1,35 @@ +package main + +import ( + "html/template" + "net/http" + "strconv" +) + +type PageData struct { + PageTitle string + CseAnswer string +} + +var data = PageData{ + PageTitle: "CSE Hello World", + CseAnswer: "", +} + +func Server() { + tmpl := template.Must(template.ParseFiles("layout.html")) + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + tmpl.Execute(w, data) + }) + http.HandleFunc("/cse", func(w http.ResponseWriter, r *http.Request) { + data.CseAnswer = "The meaning of life is " + strconv.Itoa(cse_hello()) + tmpl.Execute(w, data) + }) + http.HandleFunc("/clear", func(w http.ResponseWriter, r *http.Request) { + data.CseAnswer = "" + tmpl.Execute(w, data) + }) + if err := http.ListenAndServe(":8080", nil); err != nil { + panic(err) + } +} From 40363620368cd0ef358a704cefac00d97542e64b Mon Sep 17 00:00:00 2001 From: ljamt Date: Wed, 4 Jul 2018 09:47:58 +0200 Subject: [PATCH 02/20] #1 updating readme --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f7539aa..0a3e962 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,12 @@ # cse-server-go playground for testing go as an alternative for the cse-server -*Note* csecorec.dll and csecorecpp.dll must be manually copied into root folder - +# Get going (windows) +- install [go](https://golang.org/dl/) +- environmental variables must be defined + - [GOROOT](https://golang.org/doc/install#tarball_non_standard) - directory where go is installed + - [GOPATH](https://golang.org/cmd/go/#hdr-GOPATH_environment_variable) - where to look for Go files +- install [MinGW-w64](https://sourceforge.net/projects/mingw-w64/?source=typ_redirect) (TODO: Should investigate using VS) +- csecorec.dll and csecorecpp.dll must be manually copied into cse-server-go root folder +- go build will compile executable From 74df79d8651bd8740c1ebfb332fb60afe768740e Mon Sep 17 00:00:00 2001 From: INGSOL Date: Wed, 18 Jul 2018 14:49:13 +0200 Subject: [PATCH 03/20] Serving static files --- server.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server.go b/server.go index 695d661..1e4389f 100644 --- a/server.go +++ b/server.go @@ -21,6 +21,8 @@ func Server() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { tmpl.Execute(w, data) }) + fs := http.FileServer(http.Dir("./resources/public")) + http.Handle("/static/", http.StripPrefix("/static", fs)) http.HandleFunc("/cse", func(w http.ResponseWriter, r *http.Request) { data.CseAnswer = "The meaning of life is " + strconv.Itoa(cse_hello()) tmpl.Execute(w, data) From c51455b53a6be77d0afae7e2400bc1383c6c98c7 Mon Sep 17 00:00:00 2001 From: INGSOL Date: Wed, 18 Jul 2018 15:28:47 +0200 Subject: [PATCH 04/20] Client app added --- client/project.clj | 44 ++++++++++++++++++++++++++ client/src/cljs/cse_client/core.cljs | 27 ++++++++++++++++ client/src/cljs/cse_client/routes.cljs | 3 ++ 3 files changed, 74 insertions(+) create mode 100644 client/project.clj create mode 100644 client/src/cljs/cse_client/core.cljs create mode 100644 client/src/cljs/cse_client/routes.cljs diff --git a/client/project.clj b/client/project.clj new file mode 100644 index 0000000..025e718 --- /dev/null +++ b/client/project.clj @@ -0,0 +1,44 @@ +(defproject cse-client "1.0.0" + :min-lein-version "2.0.0" + :dependencies [[kee-frame "0.2.4" :scope "provided"] + [day8.re-frame/http-fx "0.1.6" :scope "provided"] + [cljs-ajax "0.7.3" :scope "provided"] + [org.clojure/tools.reader "1.3.0-alpha3"] + [cljsjs/bootstrap "3.3.5-0" :scope "provided"] + [org.clojure/clojurescript "1.10.339" :scope "provided"] + [org.clojure/clojure "1.9.0"]] + :plugins [[lein-count "1.0.7"] + [lein-figwheel "0.5.16"] + [lein-cljsbuild "1.1.7"]] + + :clean-targets ^{:protect false} [:target-path :compile-path "resources/public/js/compiled"] + + :source-paths ["src/clj" "src/cljc"] + + :cljsbuild {:builds [{:id "app" + :source-paths ["src/cljs" "src/cljc"] + :figwheel true + :compiler {:main cse-client.core + :asset-path "/js/compiled/out" + :output-to "../resources/public/js/compiled/app.js" + :output-dir "../resources/public/js/compiled/out" + :source-map-timestamp true + :parallel-build true + :closure-defines {cse-client.core/debug true + "re_frame.trace.trace_enabled_QMARK_" true} + :preloads [devtools.preload day8.re-frame-10x.preload] + :external-config {:devtools/config {:features-to-install [:formatters]}}}} + {:id "min" + :source-paths ["src/cljs" "src/cljc"] + :compiler {:output-to "../resources/public/js/compiled/app.js" + :optimizations :advanced + :parallel-build true}}]} + + :figwheel {:css-dirs ["resources/public/css"]} + + :profiles {:dev [:project/dev :profiles/dev] + :profiles/dev {} + :project/dev {:dependencies [[figwheel "0.5.16"] + [figwheel-sidecar "0.5.16"] + [binaryage/devtools "0.9.10"] + [day8.re-frame/re-frame-10x "0.3.3-react16"]]}}) diff --git a/client/src/cljs/cse_client/core.cljs b/client/src/cljs/cse_client/core.cljs new file mode 100644 index 0000000..764e2cc --- /dev/null +++ b/client/src/cljs/cse_client/core.cljs @@ -0,0 +1,27 @@ +(ns cse-client.core + (:require [cljsjs.bootstrap] + [cse-client.routes :as routes] + [re-frame.core :refer [dispatch subscribe dispatch-sync]] + [kee-frame.core :as k] + [day8.re-frame.http-fx] + [bidi.bidi :as bidi] + [kee-frame.api :as api])) + +(enable-console-print!) + +(def default-db {}) + +(defrecord BidiRouter [routes] + api/Router + (data->url [_ data] + (apply bidi/path-for routes data)) + (url->data [_ url] + (bidi/match-route routes url))) + +(defn root-comp [] + [:div "MORDI IS HOME"]) + +(k/start! {:router (->BidiRouter routes/routes) + :debug? true + :root-component [root-comp] + :initial-db default-db}) \ No newline at end of file diff --git a/client/src/cljs/cse_client/routes.cljs b/client/src/cljs/cse_client/routes.cljs new file mode 100644 index 0000000..0bb1894 --- /dev/null +++ b/client/src/cljs/cse_client/routes.cljs @@ -0,0 +1,3 @@ +(ns cse-client.routes) + +(def routes []) \ No newline at end of file From 5821d6751250b383e215d063f215d4188d0f13fa Mon Sep 17 00:00:00 2001 From: INGSOL Date: Wed, 18 Jul 2018 15:33:10 +0200 Subject: [PATCH 05/20] Including SPA in HTML --- layout.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/layout.html b/layout.html index 9fdf3cc..26cbff5 100644 --- a/layout.html +++ b/layout.html @@ -5,4 +5,6 @@

{{.PageTitle}}

-

{{.CseAnswer}}

\ No newline at end of file +

{{.CseAnswer}}

+ + \ No newline at end of file From cace92e0872042ee73c96cf273bb14b8c4eba9dc Mon Sep 17 00:00:00 2001 From: INGSOL Date: Thu, 19 Jul 2018 10:21:26 +0200 Subject: [PATCH 06/20] Fully working SPA part --- client/project.clj | 16 +++++++++------- client/src/cljs/cse_client/routes.cljs | 2 +- layout.html | 2 ++ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/client/project.clj b/client/project.clj index 025e718..8155661 100644 --- a/client/project.clj +++ b/client/project.clj @@ -1,17 +1,19 @@ (defproject cse-client "1.0.0" :min-lein-version "2.0.0" - :dependencies [[kee-frame "0.2.4" :scope "provided"] - [day8.re-frame/http-fx "0.1.6" :scope "provided"] - [cljs-ajax "0.7.3" :scope "provided"] + :dependencies [[kee-frame "0.2.4"] + [day8.re-frame/http-fx "0.1.6"] + [cljs-ajax "0.7.3"] + [reagent "0.8.0"] + [re-frame "0.10.5" :exclusions [reagent]] [org.clojure/tools.reader "1.3.0-alpha3"] - [cljsjs/bootstrap "3.3.5-0" :scope "provided"] - [org.clojure/clojurescript "1.10.339" :scope "provided"] + [cljsjs/bootstrap "3.3.5-0"] + [org.clojure/clojurescript "1.10.238"] [org.clojure/clojure "1.9.0"]] :plugins [[lein-count "1.0.7"] [lein-figwheel "0.5.16"] [lein-cljsbuild "1.1.7"]] - :clean-targets ^{:protect false} [:target-path :compile-path "resources/public/js/compiled"] + :clean-targets ^{:protect false} [:target-path :compile-path "../resources/public/js/compiled"] :source-paths ["src/clj" "src/cljc"] @@ -19,7 +21,7 @@ :source-paths ["src/cljs" "src/cljc"] :figwheel true :compiler {:main cse-client.core - :asset-path "/js/compiled/out" + :asset-path "/static/js/compiled/out" :output-to "../resources/public/js/compiled/app.js" :output-dir "../resources/public/js/compiled/out" :source-map-timestamp true diff --git a/client/src/cljs/cse_client/routes.cljs b/client/src/cljs/cse_client/routes.cljs index 0bb1894..8a7ef29 100644 --- a/client/src/cljs/cse_client/routes.cljs +++ b/client/src/cljs/cse_client/routes.cljs @@ -1,3 +1,3 @@ (ns cse-client.routes) -(def routes []) \ No newline at end of file +(def routes ["/" :mordi]) \ No newline at end of file diff --git a/layout.html b/layout.html index 26cbff5..e33920c 100644 --- a/layout.html +++ b/layout.html @@ -7,4 +7,6 @@

{{.PageTitle}}

{{.CseAnswer}}

+

SPA Starting here...

+
\ No newline at end of file From 67db0c5582188e9dcce57775c11ae0f3c3069bde Mon Sep 17 00:00:00 2001 From: INGSOL Date: Thu, 19 Jul 2018 10:53:42 +0200 Subject: [PATCH 07/20] Hash based routing working nicely --- client/src/cljs/cse_client/core.cljs | 17 +++++++++++++---- client/src/cljs/cse_client/routes.cljs | 3 ++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/client/src/cljs/cse_client/core.cljs b/client/src/cljs/cse_client/core.cljs index 764e2cc..0954ab6 100644 --- a/client/src/cljs/cse_client/core.cljs +++ b/client/src/cljs/cse_client/core.cljs @@ -5,7 +5,9 @@ [kee-frame.core :as k] [day8.re-frame.http-fx] [bidi.bidi :as bidi] - [kee-frame.api :as api])) + [kee-frame.api :as api] + [clojure.string :as string] + [re-frame.core :as rf])) (enable-console-print!) @@ -14,12 +16,19 @@ (defrecord BidiRouter [routes] api/Router (data->url [_ data] - (apply bidi/path-for routes data)) + (str "/#" (apply bidi/path-for routes data))) (url->data [_ url] - (bidi/match-route routes url))) + (let [[path+query fragment] (-> url (string/replace #"^/#" "") (string/split #"#" 2)) + [path query] (string/split path+query #"\?" 2)] + (some-> (bidi/match-route routes path) + (assoc :query-string query :hash fragment))))) (defn root-comp [] - [:div "MORDI IS HOME"]) + (let [route (rf/subscribe [:kee-frame/route])] + (fn [] + [:ul + [:li [:a {:href (k/path-for [:index])} "Index"]] + [:li [:a {:href (k/path-for [:article])} "Article"]]]))) (k/start! {:router (->BidiRouter routes/routes) :debug? true diff --git a/client/src/cljs/cse_client/routes.cljs b/client/src/cljs/cse_client/routes.cljs index 8a7ef29..34b9126 100644 --- a/client/src/cljs/cse_client/routes.cljs +++ b/client/src/cljs/cse_client/routes.cljs @@ -1,3 +1,4 @@ (ns cse-client.routes) -(def routes ["/" :mordi]) \ No newline at end of file +(def routes ["/" {"" :index + "fardi" :article}]) \ No newline at end of file From c737687fbbdf7b96620d941ce5d409a32b44434d Mon Sep 17 00:00:00 2001 From: INGSOL Date: Thu, 19 Jul 2018 13:49:27 +0200 Subject: [PATCH 08/20] Hash based routing working --- client/project.clj | 2 +- client/src/cljs/cse_client/core.cljs | 13 ++----------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/client/project.clj b/client/project.clj index 8155661..1a788d8 100644 --- a/client/project.clj +++ b/client/project.clj @@ -1,6 +1,6 @@ (defproject cse-client "1.0.0" :min-lein-version "2.0.0" - :dependencies [[kee-frame "0.2.4"] + :dependencies [[kee-frame "0.2.5"] [day8.re-frame/http-fx "0.1.6"] [cljs-ajax "0.7.3"] [reagent "0.8.0"] diff --git a/client/src/cljs/cse_client/core.cljs b/client/src/cljs/cse_client/core.cljs index 0954ab6..ee587bc 100644 --- a/client/src/cljs/cse_client/core.cljs +++ b/client/src/cljs/cse_client/core.cljs @@ -13,16 +13,6 @@ (def default-db {}) -(defrecord BidiRouter [routes] - api/Router - (data->url [_ data] - (str "/#" (apply bidi/path-for routes data))) - (url->data [_ url] - (let [[path+query fragment] (-> url (string/replace #"^/#" "") (string/split #"#" 2)) - [path query] (string/split path+query #"\?" 2)] - (some-> (bidi/match-route routes path) - (assoc :query-string query :hash fragment))))) - (defn root-comp [] (let [route (rf/subscribe [:kee-frame/route])] (fn [] @@ -30,7 +20,8 @@ [:li [:a {:href (k/path-for [:index])} "Index"]] [:li [:a {:href (k/path-for [:article])} "Article"]]]))) -(k/start! {:router (->BidiRouter routes/routes) +(k/start! {:routes routes/routes + :hash-routing? true :debug? true :root-component [root-comp] :initial-db default-db}) \ No newline at end of file From b40b250136b779dc5b1201e598af5d5f8db79cc8 Mon Sep 17 00:00:00 2001 From: INGSOL Date: Thu, 19 Jul 2018 15:35:35 +0200 Subject: [PATCH 09/20] Cleanup, new kee-frame --- client/project.clj | 2 +- client/src/cljs/cse_client/core.cljs | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/client/project.clj b/client/project.clj index 1a788d8..67cecb1 100644 --- a/client/project.clj +++ b/client/project.clj @@ -1,6 +1,6 @@ (defproject cse-client "1.0.0" :min-lein-version "2.0.0" - :dependencies [[kee-frame "0.2.5"] + :dependencies [[kee-frame "0.2.6"] [day8.re-frame/http-fx "0.1.6"] [cljs-ajax "0.7.3"] [reagent "0.8.0"] diff --git a/client/src/cljs/cse_client/core.cljs b/client/src/cljs/cse_client/core.cljs index ee587bc..ebc72dc 100644 --- a/client/src/cljs/cse_client/core.cljs +++ b/client/src/cljs/cse_client/core.cljs @@ -3,10 +3,6 @@ [cse-client.routes :as routes] [re-frame.core :refer [dispatch subscribe dispatch-sync]] [kee-frame.core :as k] - [day8.re-frame.http-fx] - [bidi.bidi :as bidi] - [kee-frame.api :as api] - [clojure.string :as string] [re-frame.core :as rf])) (enable-console-print!) From 75f010f65f1f742ca723b5ae626e8c718ebd8b33 Mon Sep 17 00:00:00 2001 From: INGSOL Date: Thu, 19 Jul 2018 15:42:55 +0200 Subject: [PATCH 10/20] Better route examples --- client/src/cljs/cse_client/core.cljs | 3 ++- client/src/cljs/cse_client/routes.cljs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/client/src/cljs/cse_client/core.cljs b/client/src/cljs/cse_client/core.cljs index ebc72dc..ecc89b4 100644 --- a/client/src/cljs/cse_client/core.cljs +++ b/client/src/cljs/cse_client/core.cljs @@ -14,7 +14,8 @@ (fn [] [:ul [:li [:a {:href (k/path-for [:index])} "Index"]] - [:li [:a {:href (k/path-for [:article])} "Article"]]]))) + [:li [:a {:href (k/path-for [:sub1])} "sub1"]] + [:li [:a {:href (k/path-for [:sub2])} "sub2"]]]))) (k/start! {:routes routes/routes :hash-routing? true diff --git a/client/src/cljs/cse_client/routes.cljs b/client/src/cljs/cse_client/routes.cljs index 34b9126..a7c988e 100644 --- a/client/src/cljs/cse_client/routes.cljs +++ b/client/src/cljs/cse_client/routes.cljs @@ -1,4 +1,5 @@ (ns cse-client.routes) (def routes ["/" {"" :index - "fardi" :article}]) \ No newline at end of file + "sub1" {"" :sub1 + "/sub2" :sub2}}]) \ No newline at end of file From be4f9ffca7aadd79121e24ec8311a15a203cd1d9 Mon Sep 17 00:00:00 2001 From: INGSOL Date: Thu, 19 Jul 2018 15:56:59 +0200 Subject: [PATCH 11/20] Formatting --- client/src/cljs/cse_client/routes.cljs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/cljs/cse_client/routes.cljs b/client/src/cljs/cse_client/routes.cljs index a7c988e..eff6986 100644 --- a/client/src/cljs/cse_client/routes.cljs +++ b/client/src/cljs/cse_client/routes.cljs @@ -1,5 +1,5 @@ (ns cse-client.routes) -(def routes ["/" {"" :index - "sub1" {"" :sub1 +(def routes ["/" {"" :index + "sub1" {"" :sub1 "/sub2" :sub2}}]) \ No newline at end of file From 4d63ec25b30e84d4366b262f5da12bf933456270 Mon Sep 17 00:00:00 2001 From: INGSOL Date: Thu, 19 Jul 2018 16:21:10 +0200 Subject: [PATCH 12/20] Using gorilla mux router --- Gopkg.toml | 38 ++++++++++++++++++++++++++++++++++++++ README.md | 12 ++++++++++++ server.go | 16 ++++++++-------- 3 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 Gopkg.toml diff --git a/Gopkg.toml b/Gopkg.toml new file mode 100644 index 0000000..969358f --- /dev/null +++ b/Gopkg.toml @@ -0,0 +1,38 @@ +# Gopkg.toml example +# +# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md +# for detailed Gopkg.toml documentation. +# +# required = ["github.com/user/thing/cmd/thing"] +# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] +# +# [[constraint]] +# name = "github.com/user/project" +# version = "1.0.0" +# +# [[constraint]] +# name = "github.com/user/project2" +# branch = "dev" +# source = "github.com/myfork/project2" +# +# [[override]] +# name = "github.com/x/y" +# version = "2.4.0" +# +# [prune] +# non-go = false +# go-tests = true +# unused-packages = true + + +[prune] + go-tests = true + unused-packages = true + +[[constraint]] + name = "github.com/gorilla/mux" + version = "1.6.2" + +[[constraint]] + branch = "master" + name = "github.com/codegangsta/gin" diff --git a/README.md b/README.md index 0a3e962..68bb9ed 100644 --- a/README.md +++ b/README.md @@ -10,3 +10,15 @@ playground for testing go as an alternative for the cse-server - csecorec.dll and csecorecpp.dll must be manually copied into cse-server-go root folder - go build will compile executable +# Dependencies +- Install the dep tool https://golang.github.io/dep/ +- Did establish this with a dep file in project, but needs more investigation. + +# Interactive web development (client) +- Install https://leiningen.org/ (and possibly a Java JDK) +- cd /client +- lein figwheel + +# Interactive web development (server) +- Install https://github.com/codegangsta/gin +- Did not get any further on this, but should be the way to go. \ No newline at end of file diff --git a/server.go b/server.go index 1e4389f..a4a95ea 100644 --- a/server.go +++ b/server.go @@ -4,6 +4,8 @@ import ( "html/template" "net/http" "strconv" + "github.com/gorilla/mux" + "log" ) type PageData struct { @@ -17,21 +19,19 @@ var data = PageData{ } func Server() { + router := mux.NewRouter() tmpl := template.Must(template.ParseFiles("layout.html")) - http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { tmpl.Execute(w, data) }) - fs := http.FileServer(http.Dir("./resources/public")) - http.Handle("/static/", http.StripPrefix("/static", fs)) - http.HandleFunc("/cse", func(w http.ResponseWriter, r *http.Request) { + router.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("./resources/public")))) + router.HandleFunc("/cse", func(w http.ResponseWriter, r *http.Request) { data.CseAnswer = "The meaning of life is " + strconv.Itoa(cse_hello()) tmpl.Execute(w, data) }) - http.HandleFunc("/clear", func(w http.ResponseWriter, r *http.Request) { + router.HandleFunc("/clear", func(w http.ResponseWriter, r *http.Request) { data.CseAnswer = "" tmpl.Execute(w, data) }) - if err := http.ListenAndServe(":8080", nil); err != nil { - panic(err) - } + log.Fatal(http.ListenAndServe(":8000", router)) } From 8dc78edf939876102ede378862b5cc0dddcca192 Mon Sep 17 00:00:00 2001 From: INGSOL Date: Thu, 19 Jul 2018 16:27:16 +0200 Subject: [PATCH 13/20] REST endpoint --- server.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/server.go b/server.go index a4a95ea..16ae1be 100644 --- a/server.go +++ b/server.go @@ -6,6 +6,7 @@ import ( "strconv" "github.com/gorilla/mux" "log" + "encoding/json" ) type PageData struct { @@ -18,12 +19,23 @@ var data = PageData{ CseAnswer: "", } +type Simulator struct { + ID string `json:"id,omitempty"` + Name string `json:"name,omitempty"` + Status string `json:"status,omitempty"` +} + +func RestTest(w http.ResponseWriter, r *http.Request) { + json.NewEncoder(w).Encode(Simulator{ID: "id-1", Name: "Coral", Status: "Completely broken"}) +} + func Server() { router := mux.NewRouter() tmpl := template.Must(template.ParseFiles("layout.html")) router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { tmpl.Execute(w, data) }) + router.HandleFunc("/rest-test", RestTest) router.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("./resources/public")))) router.HandleFunc("/cse", func(w http.ResponseWriter, r *http.Request) { data.CseAnswer = "The meaning of life is " + strconv.Itoa(cse_hello()) From 56ca46e6f904f21cd8b63a28c3a125d239c55251 Mon Sep 17 00:00:00 2001 From: INGSOL Date: Thu, 19 Jul 2018 16:37:40 +0200 Subject: [PATCH 14/20] REST resource loaded in SPA --- client/src/cljs/cse_client/core.cljs | 17 +++++++++++++++-- client/src/cljs/cse_client/routes.cljs | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/client/src/cljs/cse_client/core.cljs b/client/src/cljs/cse_client/core.cljs index ecc89b4..53fdf5c 100644 --- a/client/src/cljs/cse_client/core.cljs +++ b/client/src/cljs/cse_client/core.cljs @@ -3,19 +3,32 @@ [cse-client.routes :as routes] [re-frame.core :refer [dispatch subscribe dispatch-sync]] [kee-frame.core :as k] - [re-frame.core :as rf])) + [re-frame.core :as rf] + [ajax.core :as ajax])) (enable-console-print!) (def default-db {}) +(k/reg-controller :rest-demo-controller + {:params #(when (-> % :handler (= :rest-demo)) true) + :start [:load-rest-demo]}) + +(k/reg-chain :load-rest-demo + (fn [_ _] + {:http-xhrio {:method :get + :uri "/rest-test" + :response-format (ajax/json-response-format)}}) + (fn [_ [_ rest-of-it]] + (js/alert (str "GOT ME SOME REST from \"/rest-test\": " rest-of-it)))) + (defn root-comp [] (let [route (rf/subscribe [:kee-frame/route])] (fn [] [:ul [:li [:a {:href (k/path-for [:index])} "Index"]] [:li [:a {:href (k/path-for [:sub1])} "sub1"]] - [:li [:a {:href (k/path-for [:sub2])} "sub2"]]]))) + [:li [:a {:href (k/path-for [:rest-demo])} "This one is real and will load the REST"]]]))) (k/start! {:routes routes/routes :hash-routing? true diff --git a/client/src/cljs/cse_client/routes.cljs b/client/src/cljs/cse_client/routes.cljs index eff6986..574797e 100644 --- a/client/src/cljs/cse_client/routes.cljs +++ b/client/src/cljs/cse_client/routes.cljs @@ -2,4 +2,4 @@ (def routes ["/" {"" :index "sub1" {"" :sub1 - "/sub2" :sub2}}]) \ No newline at end of file + "/rest" :rest-demo}}]) \ No newline at end of file From e7174bc0f7653a4ba4e3f67d44448c64734164a4 Mon Sep 17 00:00:00 2001 From: INGSOL Date: Thu, 19 Jul 2018 16:43:39 +0200 Subject: [PATCH 15/20] Simplified for demo --- client/src/cljs/cse_client/core.cljs | 24 ++++++++++-------------- client/src/cljs/cse_client/routes.cljs | 5 ----- 2 files changed, 10 insertions(+), 19 deletions(-) delete mode 100644 client/src/cljs/cse_client/routes.cljs diff --git a/client/src/cljs/cse_client/core.cljs b/client/src/cljs/cse_client/core.cljs index 53fdf5c..1b632ab 100644 --- a/client/src/cljs/cse_client/core.cljs +++ b/client/src/cljs/cse_client/core.cljs @@ -1,14 +1,12 @@ (ns cse-client.core - (:require [cljsjs.bootstrap] - [cse-client.routes :as routes] - [re-frame.core :refer [dispatch subscribe dispatch-sync]] - [kee-frame.core :as k] - [re-frame.core :as rf] + (:require [kee-frame.core :as k] [ajax.core :as ajax])) (enable-console-print!) -(def default-db {}) +(def routes ["/" {"" :index + "sub1" {"" :sub1 + "/rest" :rest-demo}}]) (k/reg-controller :rest-demo-controller {:params #(when (-> % :handler (= :rest-demo)) true) @@ -23,15 +21,13 @@ (js/alert (str "GOT ME SOME REST from \"/rest-test\": " rest-of-it)))) (defn root-comp [] - (let [route (rf/subscribe [:kee-frame/route])] - (fn [] - [:ul - [:li [:a {:href (k/path-for [:index])} "Index"]] - [:li [:a {:href (k/path-for [:sub1])} "sub1"]] - [:li [:a {:href (k/path-for [:rest-demo])} "This one is real and will load the REST"]]]))) + [:ul + [:li [:a {:href (k/path-for [:index])} "Index"]] + [:li [:a {:href (k/path-for [:sub1])} "sub1"]] + [:li [:a {:href (k/path-for [:rest-demo])} "This one is real and will load the REST"]]]) -(k/start! {:routes routes/routes +(k/start! {:routes routes :hash-routing? true :debug? true :root-component [root-comp] - :initial-db default-db}) \ No newline at end of file + :initial-db {}}) \ No newline at end of file diff --git a/client/src/cljs/cse_client/routes.cljs b/client/src/cljs/cse_client/routes.cljs deleted file mode 100644 index 574797e..0000000 --- a/client/src/cljs/cse_client/routes.cljs +++ /dev/null @@ -1,5 +0,0 @@ -(ns cse-client.routes) - -(def routes ["/" {"" :index - "sub1" {"" :sub1 - "/rest" :rest-demo}}]) \ No newline at end of file From b693a8907b8cdeaa5c7ac05a9c35c3c472e9d337 Mon Sep 17 00:00:00 2001 From: INGSOL Date: Sat, 21 Jul 2018 11:42:55 +0200 Subject: [PATCH 16/20] Route navigation demo --- client/src/cljs/cse_client/core.cljs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/client/src/cljs/cse_client/core.cljs b/client/src/cljs/cse_client/core.cljs index 1b632ab..8fa287f 100644 --- a/client/src/cljs/cse_client/core.cljs +++ b/client/src/cljs/cse_client/core.cljs @@ -21,10 +21,16 @@ (js/alert (str "GOT ME SOME REST from \"/rest-test\": " rest-of-it)))) (defn root-comp [] - [:ul - [:li [:a {:href (k/path-for [:index])} "Index"]] - [:li [:a {:href (k/path-for [:sub1])} "sub1"]] - [:li [:a {:href (k/path-for [:rest-demo])} "This one is real and will load the REST"]]]) + [:div + [:ul + [:li [:a {:href (k/path-for [:index])} "Indexy"]] + [:li [:a {:href (k/path-for [:sub1])} "sub1"]] + [:li [:a {:href (k/path-for [:rest-demo])} "This one is real and will load the REST"]]] + [:h3 "You navigated to:"] + [k/switch-route :handler + :index "This is INDEX!!" + :sub1 "SUB1 page" + :rest-demo "You will now get an alert with downloaded simulator status"]]) (k/start! {:routes routes :hash-routing? true From a5aadd9e6531cf3b6860ee5bee7ca1741fc9abeb Mon Sep 17 00:00:00 2001 From: INGSOL Date: Tue, 24 Jul 2018 10:27:26 +0200 Subject: [PATCH 17/20] nil case for loading --- client/project.clj | 2 +- client/src/cljs/cse_client/core.cljs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/client/project.clj b/client/project.clj index 67cecb1..75549d8 100644 --- a/client/project.clj +++ b/client/project.clj @@ -1,6 +1,6 @@ (defproject cse-client "1.0.0" :min-lein-version "2.0.0" - :dependencies [[kee-frame "0.2.6"] + :dependencies [[kee-frame "0.2.7-SNAPSHOT"] [day8.re-frame/http-fx "0.1.6"] [cljs-ajax "0.7.3"] [reagent "0.8.0"] diff --git a/client/src/cljs/cse_client/core.cljs b/client/src/cljs/cse_client/core.cljs index 8fa287f..199a150 100644 --- a/client/src/cljs/cse_client/core.cljs +++ b/client/src/cljs/cse_client/core.cljs @@ -23,14 +23,15 @@ (defn root-comp [] [:div [:ul - [:li [:a {:href (k/path-for [:index])} "Indexy"]] + [:li [:a {:href (k/path-for [:index])} "Index"]] [:li [:a {:href (k/path-for [:sub1])} "sub1"]] [:li [:a {:href (k/path-for [:rest-demo])} "This one is real and will load the REST"]]] [:h3 "You navigated to:"] [k/switch-route :handler :index "This is INDEX!!" :sub1 "SUB1 page" - :rest-demo "You will now get an alert with downloaded simulator status"]]) + :rest-demo "You will now get an alert with downloaded simulator status" + nil [:div "Loading..."]]]) (k/start! {:routes routes :hash-routing? true From e1a633cd39cd6e1604a107ef63468367986c9fd8 Mon Sep 17 00:00:00 2001 From: INGSOL Date: Mon, 30 Jul 2018 15:36:44 +0200 Subject: [PATCH 18/20] Removed example deps --- Gopkg.toml | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/Gopkg.toml b/Gopkg.toml index 969358f..ba3f94b 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -1,30 +1,3 @@ -# Gopkg.toml example -# -# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md -# for detailed Gopkg.toml documentation. -# -# required = ["github.com/user/thing/cmd/thing"] -# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] -# -# [[constraint]] -# name = "github.com/user/project" -# version = "1.0.0" -# -# [[constraint]] -# name = "github.com/user/project2" -# branch = "dev" -# source = "github.com/myfork/project2" -# -# [[override]] -# name = "github.com/x/y" -# version = "2.4.0" -# -# [prune] -# non-go = false -# go-tests = true -# unused-packages = true - - [prune] go-tests = true unused-packages = true From e67c1a1ce334d281140b54cc45170c006ec01ebd Mon Sep 17 00:00:00 2001 From: INGSOL Date: Mon, 30 Jul 2018 16:08:02 +0200 Subject: [PATCH 19/20] Can't get gin to work --- Gopkg.toml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Gopkg.toml b/Gopkg.toml index ba3f94b..72f784a 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -4,8 +4,4 @@ [[constraint]] name = "github.com/gorilla/mux" - version = "1.6.2" - -[[constraint]] - branch = "master" - name = "github.com/codegangsta/gin" + version = "1.6.2" \ No newline at end of file From 1283d4ef38ae27ce6f8bf4a55e6ba62059a1eaef Mon Sep 17 00:00:00 2001 From: ljamt Date: Mon, 13 Aug 2018 14:57:54 +0200 Subject: [PATCH 20/20] #1 preventing figwheel from failing with non existing folder cljc --- client/project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/project.clj b/client/project.clj index 75549d8..08dd692 100644 --- a/client/project.clj +++ b/client/project.clj @@ -18,7 +18,7 @@ :source-paths ["src/clj" "src/cljc"] :cljsbuild {:builds [{:id "app" - :source-paths ["src/cljs" "src/cljc"] + :source-paths ["src/cljs"] :figwheel true :compiler {:main cse-client.core :asset-path "/static/js/compiled/out"