Commits

Miki Tebeka committed 1140e6b

No presentation

  • Participants
  • Parent commits 14ead55

Comments (0)

Files changed (30)

1-hello-appengine/app.yaml

+application: shortie
+version: 1
+runtime: go
+api_version: go1
+
+handlers:
+- url: /.*
+  script: _go_app

1-hello-appengine/run-local.sh

+#!/bin/bash
+# Run server locally
+
+/opt/google_appengine_go/dev_appserver.py . $@

1-hello-appengine/shortie/shortie.go

+/* AppEngine demo - a URL shortener */
+package shortie
+
+import (
+	"fmt"
+	"net/http"
+)
+
+func init() {
+	http.HandleFunc("/", rootHandler)
+}
+
+// rootHandler handles the main page.
+func rootHandler(w http.ResponseWriter, r *http.Request) {
+	fmt.Fprintf(w, "Hello AppEngine\n")
+}

2-template/app.yaml

+application: shortie
+version: 1
+runtime: go
+api_version: go1
+
+handlers:
+- url: /.*
+  script: _go_app

2-template/run-local.sh

+#!/bin/bash
+# Run server locally
+
+/opt/google_appengine_go/dev_appserver.py . $@

2-template/shortie/html.go

+package shortie
+
+const homeHTML = `
+<html>
+    <head>
+        <title>Shortie - The URL Shortener</title>
+        <link rel="stylesheet" href="/static/style.css" />
+        <link rel="shortcut icon" href="/static/logo.png" />
+    </head>
+    <body>
+        <div class="header">
+            The URL Shortener
+            <span class="right">
+				<a href="{{ .LoginURL }}">{{ .LoginTitle }}</a>
+            </span>
+        </div>
+
+        {{ if .ShortURL }}
+        <div class="short">
+            Url shortened to <a href="{{ .ShortURL }}">{{ .ShortURL }}</a>
+        </div>
+        {{ end }}
+
+        {{ if .Error }}
+        <div class="error">
+            ERROR: {{ .Error | html}}
+        </div>
+        {{ end }}
+
+        <form method="post">
+            <label for="url">Url:</label><input name="url" /> 
+            <input type="submit" value="Shorten">
+        </form>
+
+		{{ with .URLs }}
+        <b>Your Urls</b>
+        <table class="urls">
+            <tr><th>URL</th><th>Created</th><th>Hits</th></tr>
+			{{ range $idx, $url := . }}
+				<tr class="{{ $idx | oddeven }}">
+					<td title="{{ .Long | html }}">
+						<a href="{{ .Long }}">{{ .Short }}</a>
+					</td>
+					<td>{{ .Created | strftime }}</td>
+					<td>{{ .Hits }}</td>
+            </tr>
+            {{ end }}
+        </table>
+        {{ end }}
+
+        <div class="footer">
+            G'day {{ .User }}, we've shortened {{ .Count }} urls so far.
+        </div>
+	</body>
+</html>
+`
+
+// vim: ft=html

2-template/shortie/shortie.go

+/* AppEngine demo - a URL shortener */
+package shortie
+
+import (
+	"fmt"
+	"net/http"
+)
+
+func init() {
+	http.HandleFunc("/", rootHandler)
+}
+
+// rootHandler handles the main page.
+func rootHandler(w http.ResponseWriter, r *http.Request) {
+	fmt.Fprintf(w, "Hello AppEngine\n")
+}

2-template/static/logo.png

Added
New image

2-template/static/style.css

+body {
+    margin: 20px;
+    border: 2px solid blue;
+    padding: 1px;
+}
+
+input[name=url] {
+    width: 80%;
+    margin-left: 4px;
+}
+
+span.right {
+    float: right;
+    margin-right: 5px;
+}
+
+div.header {
+    padding: 2px;
+    background: silver;
+    border-bottom: 1px solid gray;
+    margin-bottom: 10px;
+}
+
+table.urls {
+    border-collapse: collapse;
+    width: 100%;
+    border: 1px dashed blue;
+}
+
+table.urls th {
+    text-align: left;
+}
+
+div.footer {
+    margin-top: 10px;
+    padding-top: 5px;
+    border-top: 1px dashed gray;
+    padding-left: 10px;
+    font-family: Monospace;
+}
+
+div.error {
+    color: red;
+}
+
+tr.even {
+    background: #DCDCDC;
+}

Makefile

-html = go-appengine.html
-
-all: $(html)
-
-$(html): go-appengine.txt src/*
-	asciidoc -a stylesheet=${PWD}/style.css $<
-
-clean:
-	rm -f $(html)
-
-fresh: clean all
-
-.PHONY: all clean fresh

go-appengine.txt

-Go On AppEngine
-===============
-:author: Miki Tebeka <miki@adconion.com>
-:backend: slidy
-:max-width: 45em
-:data-uri:
-:icons:
-
-Disclaimer
-----------
-* I'm not an expert
-* Not a Go expert
-* Not an AppEngine expert
-* This is just me playing around
-* There's probably a better way to do it (TM)
-
-Now that this is out of the way ...
-
-
-Why AppEngine?
---------------
-"Google App Engine enables you to build web applications on the same scalable
-systems that power Google applications. App Engine applications are easy to
-build, easy to maintain, and easy to scale as your traffic and data storage
-needs grow. With App Engine, there are no servers to maintain: You just upload
-your application, and it's ready to serve to your user."
-
-https://developers.google.com/appengine/whyappengine
-
-
-Why Go?
--------
-I *guess* you know most of the answer :)
-
-As a plus, in AppEngine Go will save you money due to less resource consumption.
-
-What Do You Get?
-----------------
-* Scaling
-* Data Store
-* User management
-* Memcached
-* Mail
-* Task Queue
-* XMPP
-* Logging
-* ...
-
-
-
-A Toy Application - URL Shortener
----------------------------------
-
-
-Hello AppEngine - Configuration
--------------------------------
-[source,yaml,numbered]
----------------------------------------------------
-include::src/1/app.yaml[]
----------------------------------------------------
-
-Hello AppEngine - Code
-----------------------
-[source,go,numbered]
----------------------------------------------------
-include::src/1/shortie/shortie.go[]
----------------------------------------------------
-
-// vim: ft=asciidoc spell

images/icons/callouts/1.png

Removed
Old image

images/icons/callouts/10.png

Removed
Old image

images/icons/callouts/11.png

Removed
Old image

images/icons/callouts/12.png

Removed
Old image

images/icons/callouts/13.png

Removed
Old image

images/icons/callouts/14.png

Removed
Old image

images/icons/callouts/15.png

Removed
Old image

images/icons/callouts/2.png

Removed
Old image

images/icons/callouts/3.png

Removed
Old image

images/icons/callouts/4.png

Removed
Old image

images/icons/callouts/5.png

Removed
Old image

images/icons/callouts/6.png

Removed
Old image

images/icons/callouts/7.png

Removed
Old image

images/icons/callouts/8.png

Removed
Old image

images/icons/callouts/9.png

Removed
Old image

src/1-hello-appengine/app.yaml

-application: shortie
-version: 1
-runtime: go
-api_version: go1
-
-handlers:
-- url: /.*
-  script: _go_app

src/1-hello-appengine/run-local.sh

-#!/bin/bash
-# Run server locally
-
-/opt/google_appengine_go/dev_appserver.py . $@

src/1-hello-appengine/shortie/shortie.go

-/* AppEngine demo - a URL shortener */
-package shortie
-
-import (
-	"fmt"
-	"net/http"
-)
-
-func init() {
-	http.HandleFunc("/", rootHandler)
-}
-
-// rootHandler handles the main page.
-func rootHandler(w http.ResponseWriter, r *http.Request) {
-	fmt.Fprintf(w, "Hello AppEngine\n")
-}

style.css

-/* Vertical lines between line numbers and code */
-div.linenodiv {
-    border-right:1px solid gray;
-    padding-right:2px;
-    margin-right:2px;
-}