Browse Source

go-raw: embed fortune template in the code

This has no performance impact however it makes it easier to deploy the
application as only one file is required.
Konstantin Shaposhnikov 9 years ago
parent
commit
f0fd5194d8

+ 0 - 3
frameworks/Go/go-raw/source_code

@@ -1,6 +1,3 @@
 ./go/src/
 ./go/src/hello
 ./go/src/hello/hello.go
-./go/templates/
-./go/templates/fortune.html
-./go/templates/layout.html

+ 22 - 1
frameworks/Go/go-raw/src/hello/hello.go

@@ -34,7 +34,28 @@ type Fortune struct {
 }
 
 const (
+	// Content
 	helloWorldString = "Hello, World!"
+	fortuneHTML      = `<!DOCTYPE html>
+<html>
+<head>
+<title>Fortunes</title>
+</head>
+<body>
+<table>
+<tr>
+<th>id</th>
+<th>message</th>
+</tr>
+{{range .}}
+<tr>
+<td>{{.Id}}</td>
+<td>{{.Message}}</td>
+</tr>
+{{end}}
+</table>
+</body>
+</html>`
 
 	// Databases
 	//
@@ -54,7 +75,7 @@ var (
 	helloWorldBytes = []byte(helloWorldString)
 
 	// Templates
-	tmpl = template.Must(template.ParseFiles("templates/layout.html", "templates/fortune.html"))
+	tmpl = template.Must(template.New("fortune.html").Parse(fortuneHTML))
 
 	// Database
 	db                    *sql.DB

+ 0 - 14
frameworks/Go/go-raw/templates/fortune.html

@@ -1,14 +0,0 @@
-{{define "content"}}
-<table>
-<tr>
-<th>id</th>
-<th>message</th>
-</tr>
-{{range .}}
-<tr>
-<td>{{.Id}}</td>
-<td>{{.Message}}</td>
-</tr>
-{{end}}
-</table>
-{{end}}

+ 0 - 9
frameworks/Go/go-raw/templates/layout.html

@@ -1,9 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-<title>Fortunes</title>
-</head>
-<body>
-{{template "content" .}}
-</body>
-</html>