-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from go-labx/feature/support-template
feat: support template engine and static file hosting
- Loading branch information
Showing
8 changed files
with
124 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/go-labx/lightning" | ||
"html/template" | ||
"time" | ||
) | ||
|
||
func formatDate(t time.Time) string { | ||
year, month, day := t.Date() | ||
return fmt.Sprintf("%d-%02d-%02d", year, month, day) | ||
} | ||
|
||
func main() { | ||
// Create a new Lightning app | ||
app := lightning.DefaultApp() | ||
|
||
app.Static("./public", "/static") | ||
app.SetFuncMap(template.FuncMap{ | ||
"formatDate": formatDate, | ||
}) | ||
app.LoadHTMLGlob("templates/*") | ||
|
||
app.Get("/", func(ctx *lightning.Context) { | ||
ctx.HTML(200, "index.tmpl", lightning.Map{ | ||
"title": "Lightning", | ||
"description": "Lightning is a lightweight and fast web framework for Go. It is designed to be easy to use and highly performant. ⚡️⚡️⚡️", | ||
"now": time.Now(), | ||
}) | ||
}) | ||
|
||
// Run the app | ||
app.Run() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
body { | ||
background-color: cyan; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log("hello world") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Document</title> | ||
<link rel="stylesheet" href="/static/css/1.css" /> | ||
<script src="/static/js/1.js"></script> | ||
</head> | ||
<body> | ||
<h2>{{.title}}</h2> | ||
<p>{{.description}}</p> | ||
<p>{{.now | formatDate }}</p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters