Browse Source

Initial import

Wirecog 7 years ago
commit
38c73fb86c
9 changed files with 212 additions and 0 deletions
  1. 8
    0
      .gitignore
  2. 29
    0
      LICENSE
  3. 57
    0
      Readme.md
  4. 11
    0
      client/client.go
  5. 53
    0
      isogoapp.go
  6. 29
    0
      static/css/style.css
  7. BIN
      static/images/isomorphic_go_icon.png
  8. BIN
      static/images/isomorphic_go_logo.png
  9. 25
    0
      templates/index.html

+ 8
- 0
.gitignore View File

@@ -0,0 +1,8 @@
1
+*~
2
+*.swp
3
+*.swo
4
+*.tmp
5
+*.out
6
+.DS_Store
7
+*.js
8
+*.js.map

+ 29
- 0
LICENSE View File

@@ -0,0 +1,29 @@
1
+The Isomorphic Go Project
2
+Copyright (c) Wirecog, LLC. All rights reserved.
3
+
4
+Redistribution and use in source and binary forms, with or without
5
+modification, are permitted provided that the following conditions are
6
+met:
7
+
8
+   * Redistributions of source code must retain the above copyright
9
+notice, this list of conditions and the following disclaimer.
10
+   * Redistributions in binary form must reproduce the above
11
+copyright notice, this list of conditions and the following disclaimer
12
+in the documentation and/or other materials provided with the
13
+distribution.
14
+   * Neither the name of Wirecog, LLC. nor the names of its contributors
15
+may be used to endorse or promote products derived from
16
+this software without specific prior written permission.
17
+
18
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
+

+ 57
- 0
Readme.md View File

@@ -0,0 +1,57 @@
1
+<p align="center"><a href="http://isomorphicgo.org" target="_blank"><img src="https://github.com/isomorphicgo/isogoapp/blob/master/static/images/isomorphic_go_logo.png"></a></p>
2
+
3
+# Isomorphic Go App (isogoapp)
4
+
5
+A basic, barebones web app, intented to be used as a starting point for developing an [Isomorphic Go](http://isomorphicgo.org) application.
6
+
7
+## Installation
8
+
9
+The instructions assume that you are using a Unix-like operating system (e.g. BSD, Linux, Mac OS, etc).
10
+
11
+If you are using Windows, you may need to adapt the installation instructions, most notably for setting up the `ISOGO_APP_ROOT` environment variable.
12
+
13
+### Prerequisites
14
+
15
+It is assumed that the latest version of Go is already installed on your system and that you have properly configured your Go workspace.
16
+
17
+### Get the isogoapp project
18
+`go get -u github.com/isomorphicgo/isogoapp`
19
+
20
+
21
+### Define the `ISOGO_APP_ROOT` environment variable.
22
+`export ISOGO_APP_ROOT=${GOPATH}/src/github.com/isomorphicgo/isogoapp`
23
+
24
+
25
+### Build the Client-Side Go App
26
+`cd $ISOGO_APP_ROOT/client`
27
+
28
+`gopherjs build`
29
+
30
+### Run the Web Server Instance
31
+
32
+`cd $ISOGO_APP_ROOT`
33
+
34
+`go run isogoapp.go`
35
+
36
+
37
+The web server runs locally on port 8080: [localhost:8080](http://localhost:8080).
38
+
39
+If all goes well, you should see the Isomorphic Go logo, along with a message rendered on the web page.
40
+
41
+
42
+## Where to now?
43
+
44
+### Kick
45
+
46
+Once you've installed, and confirmed, that the basic Isomorphic Go application is working, the next logical step is to install [Kick](https://github.com/isomorphicgo/kick).
47
+
48
+Kick automatically recompiles Go code, and it can take both the `go` and `gopherjs` commands into consideration. 
49
+
50
+Kick performs an *instant kickstart* of the web server instance, upon the modification of a Go source file. [Check out Kick](https://github.com/isomorphicgo/kick)
51
+
52
+### The Isomorphic Go Project
53
+More information on the benefits of Isomorphic Go applications can be found at the [Isomorphic Go Website](http://isomorphicgo.org).
54
+
55
+## License
56
+The `isogoapp` is licensed under the BSD License. Read the [LICENSE](https://github.com/isomorphicgo/isogoapp/blob/master/LICENSE) file for more information.
57
+

+ 11
- 0
client/client.go View File

@@ -0,0 +1,11 @@
1
+package main
2
+
3
+import "honnef.co/go/js/dom"
4
+
5
+func main() {
6
+
7
+	println("The sample Isomorphic Go skeleton web app successfully printed to your web browser console using GopherJS!")
8
+	d := dom.GetWindow().Document()
9
+	h := d.GetElementByID("welcomeMessage")
10
+	h.SetInnerHTML("<p>The sample Isomorphic Go skeleton web app is working successfully.</p><p>GopherJS was used to print this welcome message.</p><p>There's another message waiting in your web browser console.</p>")
11
+}

+ 53
- 0
isogoapp.go View File

@@ -0,0 +1,53 @@
1
+package main
2
+
3
+import (
4
+	"fmt"
5
+	"html/template"
6
+	"log"
7
+	"net/http"
8
+	"os"
9
+
10
+	"github.com/gorilla/mux"
11
+)
12
+
13
+var webappRoot string = os.Getenv("ISOGO_APP_ROOT")
14
+
15
+func indexHandler(w http.ResponseWriter, r *http.Request) {
16
+	renderTemplate(w, webappRoot+"/templates/index.html", nil)
17
+}
18
+
19
+// Template rendering function
20
+func renderTemplate(w http.ResponseWriter, templateFile string, templateData interface{}) {
21
+
22
+	t, err := template.ParseFiles(templateFile)
23
+	if err != nil {
24
+		log.Fatal("Error encountered while parsing the template: ", err)
25
+	}
26
+	t.Execute(w, templateData)
27
+}
28
+
29
+func gopherjsScriptHandler(w http.ResponseWriter, r *http.Request) {
30
+	http.ServeFile(w, r, webappRoot+"/client/client.js")
31
+}
32
+
33
+func gopherjsScriptMapHandler(w http.ResponseWriter, r *http.Request) {
34
+	http.ServeFile(w, r, webappRoot+"/client/client.js.map")
35
+}
36
+
37
+func main() {
38
+
39
+	if webappRoot == "" {
40
+		fmt.Println("The ISOGO_APP_ROOT environment variable must be set before the web server instance can be started.")
41
+		os.Exit(1)
42
+	}
43
+
44
+	fs := http.FileServer(http.Dir(webappRoot + "/static"))
45
+	r := mux.NewRouter()
46
+	r.HandleFunc("/", indexHandler)
47
+	r.HandleFunc("/js/client.js", gopherjsScriptHandler)
48
+	r.HandleFunc("/js/client.js.map", gopherjsScriptMapHandler)
49
+	http.Handle("/", r)
50
+	http.Handle("/static/", http.StripPrefix("/static", fs))
51
+	http.ListenAndServe(":8080", nil)
52
+
53
+}

+ 29
- 0
static/css/style.css View File

@@ -0,0 +1,29 @@
1
+body {
2
+	font-family: arial,helvetica;
3
+	font-size: 12pt;
4
+}
5
+
6
+#welcomeContainer {
7
+	padding-top: 3px;
8
+	text-align: center;
9
+}
10
+
11
+#welcomeMessage {
12
+	margin-top: 54px;
13
+}
14
+
15
+#copyright_notice {
16
+	display: block;
17
+	text-align: center;
18
+	margin: 0;
19
+	margin-bottom:9px;
20
+	width: 100%;
21
+}
22
+
23
+#copyright_notice p {
24
+	font-size: 9pt;
25
+}
26
+
27
+footer {
28
+	margin-top: 72px;
29
+}

BIN
static/images/isomorphic_go_icon.png View File


BIN
static/images/isomorphic_go_logo.png View File


+ 25
- 0
templates/index.html View File

@@ -0,0 +1,25 @@
1
+<html>
2
+<head>
3
+<link rel="stylesheet" type="text/css" href="/static/css/style.css">
4
+<link rel="icon" type="image/png" href="/static/images/isomorphic_go_icon.png">
5
+</head>
6
+<body>
7
+
8
+<div id="welcomeContainer">
9
+<h1>Hello Gopher!</h1>
10
+<br/>
11
+<a target="_blank" href="http://isomorphicgo.org"><img border="0" src="/static/images/isomorphic_go_logo.png"></a>
12
+
13
+<div id="welcomeMessage"></div>
14
+
15
+<script src="/js/client.js" async></script>
16
+</div>
17
+
18
+<footer>
19
+<div id="copyright_notice">
20
+<p>Copyright &copy; <a target="_blank" href="http://isomorphicgo.org">The Isomorphic Go Project</a>. All Rights Reserved</p>
21
+</div>
22
+</footer>
23
+
24
+</body>
25
+</html>