Browse Source

Draft version.

Alex Myasoedov 8 years ago
parent
commit
50a780483f
4 changed files with 144 additions and 0 deletions
  1. 24 0
      .gitignore
  2. 40 0
      app_test.go
  3. 46 0
      main.go
  4. 34 0
      templates/index.tmpl

+ 24 - 0
.gitignore

@@ -0,0 +1,24 @@
+# Compiled Object files, Static and Dynamic libs (Shared Objects)
+*.o
+*.a
+*.so
+
+# Folders
+_obj
+_test
+
+# Architecture specific extensions/prefixes
+*.[568vq]
+[568vq].out
+
+*.cgo1.go
+*.cgo2.c
+_cgo_defun.c
+_cgo_gotypes.go
+_cgo_export.*
+
+_testmain.go
+
+*.exe
+bin/
+src/

+ 40 - 0
app_test.go

@@ -0,0 +1,40 @@
+package main
+
+import (
+	. "github.com/franela/goblin"
+	"net/http"
+	"net/http/httptest"
+	"testing"
+)
+
+func performRequest(method, path string) *httptest.ResponseRecorder {
+  app := NewApp()
+  req, _ := http.NewRequest(method, path, nil)
+	w := httptest.NewRecorder()
+	app.ServeHTTP(w, req)
+	return w
+}
+
+func Test(t *testing.T) {
+	g := Goblin(t)
+	g.Describe("App api", func() {
+
+		g.It("Should return 200 on / ", func() {
+      w := performRequest("GET", "/")
+			g.Assert(w.Code).Equal(200)
+		})
+
+		g.It("Should return 200 on /slides.md ", func() {
+      w := performRequest("GET", "/slides.md")
+			g.Assert(w.Code).Equal(200)
+		})
+
+		g.It("Should return 200 on PUT /slides.md ", func() {
+      w := performRequest("PUT", "/slides.md")
+			g.Assert(w.Code).Equal(200)
+		})
+
+		g.It("Should works")
+
+	})
+}

+ 46 - 0
main.go

@@ -0,0 +1,46 @@
+package main
+
+import (
+	"github.com/gin-gonic/gin"
+	"io/ioutil"
+)
+
+var DB = make(map[string]string)
+
+func NewApp() *gin.Engine {
+
+	r := gin.Default()
+
+	r.GET("/slides.md", func(c *gin.Context) {
+		body, err := ioutil.ReadFile("initial-slides.md")
+		if err != nil {
+			panic(err)
+		}
+		c.String(200, string(body))
+	})
+
+	r.GET("/", func(c *gin.Context) {
+		c.HTML(200, "index.tmpl", gin.H{
+			"pubTo": "Users",
+		})
+	})
+
+	// Get user value
+	r.GET("/user/:name", func(c *gin.Context) {
+		user := c.Params.ByName("name")
+		value, ok := DB[user]
+		if ok {
+			c.JSON(200, gin.H{"user": user, "value": value})
+		} else {
+			c.JSON(200, gin.H{"user": user, "status": "no value"})
+		}
+	})
+
+	return r
+
+}
+
+func main() {
+	r := NewApp()
+	r.Run(":8080")
+}

+ 34 - 0
templates/index.tmpl

@@ -0,0 +1,34 @@
+{{ define "users/index.tmpl" }}
+
+<!doctype html>
+<html lang="en">
+
+    <head>
+        <meta charset="utf-8">
+
+        <title>Hacker Slides</title>
+
+        <link rel="stylesheet" href="/static/css/index.css">
+    </head>
+
+    <body>
+        <div id="edit-pane">
+          <div id="controls">
+            <a href="{{ .pubTo }}" target="_blank" onclick="save();"> Present</a>
+          </div>
+          <div id="editor"></div>
+        </div>
+
+        <div id="preview">
+            <iframe id="slides-frame" src="/static/slides.html?preview"></iframe>
+        </div>
+
+        <script src="/static/revealjs/js/ace-1.1.8/ace.js" type="text/javascript" charset="utf-8"></script>
+        <script src="/static/revealjs/js/jquery-2.1.3.min.js" type="text/javascript" charset="utf-8"></script>
+        <script src="/static/revealjs/js/jquery-debounce-1.0.5.js" type="text/javascript" charset="utf-8"></script>
+        <script src="/static/js/save.js" type="text/javascript" charset="utf-8"></script>
+        <script src="/static/js/index.js" type="text/javascript" charset="utf-8"></script>
+    </body>
+</html>
+
+{{ end }}