-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from open-simulation-platform/issue/1-set-up-go…
…-server-requesting-cse-core Issue/1 set up go server requesting cse core
- Loading branch information
Showing
9 changed files
with
202 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,5 @@ | |
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[prune] | ||
go-tests = true | ||
unused-packages = true | ||
|
||
[[constraint]] | ||
name = "github.com/gorilla/mux" | ||
version = "1.6.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,24 @@ | ||
# cse-server-go | ||
playground for testing go as an alternative for the cse-server | ||
|
||
# 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 | ||
|
||
# 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
(defproject cse-client "1.0.0" | ||
:min-lein-version "2.0.0" | ||
:dependencies [[kee-frame "0.2.7-SNAPSHOT"] | ||
[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"] | ||
[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"] | ||
|
||
:source-paths ["src/clj" "src/cljc"] | ||
|
||
:cljsbuild {:builds [{:id "app" | ||
:source-paths ["src/cljs"] | ||
:figwheel true | ||
:compiler {:main cse-client.core | ||
: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 | ||
: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"]]}}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
(ns cse-client.core | ||
(:require [kee-frame.core :as k] | ||
[ajax.core :as ajax])) | ||
|
||
(enable-console-print!) | ||
|
||
(def routes ["/" {"" :index | ||
"sub1" {"" :sub1 | ||
"/rest" :rest-demo}}]) | ||
|
||
(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 [] | ||
[:div | ||
[: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"]]] | ||
[: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" | ||
nil [:div "Loading..."]]]) | ||
|
||
(k/start! {:routes routes | ||
:hash-routing? true | ||
:debug? true | ||
:root-component [root-comp] | ||
:initial-db {}}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<h1>{{.PageTitle}} </h1> | ||
<form action="/cse"> | ||
<input type="submit" value="Ask CSE for meaning of life"> | ||
</form> | ||
<form action="/clear"> | ||
<input type="submit" value="Clear"> | ||
</form> | ||
<h2>{{.CseAnswer}}</h2> | ||
|
||
<h1>SPA Starting here...</h1> | ||
<div id="app"></div> | ||
<script src="/static/js/compiled/app.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package main | ||
|
||
func main() { | ||
Server() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package main | ||
|
||
import ( | ||
"html/template" | ||
"net/http" | ||
"strconv" | ||
"github.com/gorilla/mux" | ||
"log" | ||
"encoding/json" | ||
) | ||
|
||
type PageData struct { | ||
PageTitle string | ||
CseAnswer string | ||
} | ||
|
||
var data = PageData{ | ||
PageTitle: "CSE Hello World", | ||
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()) | ||
tmpl.Execute(w, data) | ||
}) | ||
router.HandleFunc("/clear", func(w http.ResponseWriter, r *http.Request) { | ||
data.CseAnswer = "" | ||
tmpl.Execute(w, data) | ||
}) | ||
log.Fatal(http.ListenAndServe(":8000", router)) | ||
} |