Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/krisnova/bjorno
Go HTTP server built for runtime interpolation with text/template.
https://github.com/krisnova/bjorno
dynamic go golang hello hugo interpolate runtime static webserver
Last synced: 4 months ago
JSON representation
Go HTTP server built for runtime interpolation with text/template.
- Host: GitHub
- URL: https://github.com/krisnova/bjorno
- Owner: krisnova
- License: apache-2.0
- Created: 2021-04-21T23:21:53.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-12-28T22:33:21.000Z (about 3 years ago)
- Last Synced: 2024-06-21T18:08:16.090Z (7 months ago)
- Topics: dynamic, go, golang, hello, hugo, interpolate, runtime, static, webserver
- Language: Go
- Homepage: https://nivenly.com
- Size: 1.03 MB
- Stars: 9
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bjorno
Bjorno is a recursive HTTP web server. It can be used with [hugo](https://github.com/gohugoio/hugo) and themes like [docsy](https://github.com/google/docsy) to add dynamic data to your website at runtime.
Bjorno serves static content, and also offers the following features.
- Easy way to build custom routes/endpoints on top of static content.
- Easy way to interpolate static content at runtime.# Using bjorno
You can build a custom application in Go and vendor bjorno directly into your program.
## sample/index.html
```html
{{ .Name }}
Welcome to {{ .Name }}
My nickname is {{ .Nickname }}
```
#### main.go
Build a file and define the webserver components as well as the runtime program components.
```go
package mainimport (
"sync"bjorno "github.com/kris-nova/bjorno"
)func main() {
cfg := &bjorno.ServerConfig{
InterpolateExtensions: []string{
".html",
},
BindAddress: ":1313",
ServeDirectory: "sample/",
DefaultIndexFiles: []string{
"index.html",
},
}
bjorno.Runtime(cfg, &BjornoProgram{
Name: "Björn",
Nickname: "Pupperscotch",
})}
type BjornoProgram struct {
Name string
Nickname string
mutex sync.Mutex
}func (v *BjornoProgram) Values() interface{} {
return v
}func (v *BjornoProgram) Refresh() {
v.Nickname = "butterscotch"
v.Name = "björn"
}func (v *BjornoProgram) Lock() {
v.mutex.Lock()
}func (v *BjornoProgram) Unlock() {
v.mutex.Unlock()
}```
#### Run your web application
```bash
go run main.go
```Now open your browser to `localhost:1313` and you will see your values interpolated on the webpage.
Simply change your program to do what you need it to do.
Whatever `.Values()` returns in your program will be interpolated according to [text/template](https://golang.org/pkg/text/template/).