Skip to content

Commit

Permalink
Add go net/http
Browse files Browse the repository at this point in the history
  • Loading branch information
yoavlt committed Nov 11, 2015
1 parent b1ea578 commit 02f7cc6
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clj/start_app.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

lein run -m clj.core
Binary file added go/go
Binary file not shown.
35 changes: 35 additions & 0 deletions go/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"fmt"
"github.com/julienschmidt/httprouter"
"html/template"
"log"
"net/http"
)

var NAMES = []string{"yoavlt", "entotsu", "morishitter"}

func RenderHtml(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
tmpl := template.Must(template.ParseFiles("views/index.html"))

err := tmpl.ExecuteTemplate(w, "base", NAMES)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}

func RenderName(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
fmt.Fprintf(w, "Hello, %s!", ps.ByName("name"))
}

func main() {
router := httprouter.New()
router.GET("/body/:name", RenderName)
router.GET("/render/html", RenderHtml)

err := http.ListenAndServe(":4001", router)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
34 changes: 34 additions & 0 deletions go/views/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{{define "base"}}
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">

<title>マンメンミ</title>
</head>

<body>
<div class="container">
<div class="header">
<span class="logo"></span>
</div>

<ul>
{{range .}}
<li>
<p>{{.}}</p>
</li>
{{end}}
</ul>

<div class="footer">
</div>

</div> <!-- /container -->
</body>
</html>
{{end}}
4 changes: 4 additions & 0 deletions plug_app/start_app.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

MIX_ENV=prod mix do deps.get, compile
MIX_ENV=prod elixir -pa _build/prod/consolidated -S mix server

0 comments on commit 02f7cc6

Please sign in to comment.