A simple and lightweight server-side web framework for Go, that works like Flask, but in an ambient that is much faster than Python. You can send data through the data
interface and use HTML files as templates.
go get github.com/aquiffoo/goblet
package main
import (
"net/http"
"github.com/aquiffoo/goblet"
)
func main() {
app := goblet.New(true)
app.Handle("/", func(w http.ResponseWriter, r *http.Request) {
data := map[string]interface{}{
"title": "Home",
}
app.Render(w, "index.html", data)
})
app.Handle("/about", func(w http.ResponseWriter, r *http.Request) {
data := map[string]interface{}{
"title": "About",
}
app.Render(w, "about.html", data)
})
err := app.Serve("8080")
if err != nil {
panic(err)
}
}
<!-- index.html -->
<!DOCTYPE html>
<html lang="{{ .lang }}">
<head>
<meta charset="{{ .charset }}">
<title>{{ .title }}</title>
<link rel="stylesheet" href="{{ url_for "static/style.css" }}">
</head>
<body>
<h1>Welcome to Goblet</h1>
<p>This is a demo for Goblet, my first Go framework.</p>
<a href="{{ url_for "about" }}">About</a>
</body>
</html>
<!-- about.html -->
<!DOCTYPE html>
<html lang="{{ .lang }}">
<head>
<meta charset="{{ .charset }}">
<title>{{ .title }}</title>
<link rel="stylesheet" href="{{ url_for "static/style.css" }}">
</head>
<body>
<h1>About Page</h1>
<p>This page is rendered using Goblet templates.</p>
<a href="{{ url_for "index" }}">Go Back</a>
</body>
</html>
The documentation can be found here.
This project is licensed under the CC BY-NC 4.0 license.
This was entirely written by aquiffoo. Contributors can add their names to the AUTHORS file.