https://github.com/sauldoescode/transplacer
it reads files & suspends them in memory for performant serving/access
https://github.com/sauldoescode/transplacer
assetcache cache http2 http2-push memory-database push serving static
Last synced: 15 days ago
JSON representation
it reads files & suspends them in memory for performant serving/access
- Host: GitHub
- URL: https://github.com/sauldoescode/transplacer
- Owner: SaulDoesCode
- License: mpl-2.0
- Created: 2018-11-08T13:56:26.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-11-24T11:30:43.000Z (about 7 years ago)
- Last Synced: 2025-02-23T09:43:29.011Z (11 months ago)
- Topics: assetcache, cache, http2, http2-push, memory-database, push, serving, static
- Language: Go
- Homepage:
- Size: 78.1 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](http://godoc.org/github.com/SaulDoesCode/transplacer)
## Features
* auto http2 push, when available
* auto watching and updating
* gzips and sets etags
* works concurrently, no deadlocks
* it's a bit of rough magic & ducktape, but, it works
## Diy AssetCache for super fast static asset serving straight from the memory
```go
package main
import (
"log"
"net/http"
"time"
tr "github.com/SaulDoesCode/transplacer"
)
func main() {
cache, err := tr.Make(&tr.AssetCache{
Dir: "./assets",
Watch: true,
Expire: time.Minute * 30,
DevMode: true, // extra logs
})
if err != nil {
panic(err.Error())
}
defer cache.Close()
server := &http.Server{
Addr: ":http",
Handler: cache,
}
log.Fatal(server.ListenAndServe())
}
```
With Echo
```go
package main
import (
"time"
tr "github.com/SaulDoesCode/transplacer"
"github.com/labstack/echo"
)
func main() {
cache, err := tr.Make(&tr.AssetCache{
Dir: "./assets",
Watch: true,
Expire: time.Minute * 30,
})
if err != nil {
panic(err.Error())
}
defer cache.Close()
e := echo.New()
e.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
req := c.Request()
err := next(c)
if err == nil || req.Method[0] != 'G' {
return err
}
return cache.Serve(c.Response().Writer, req)
}
})
e.Logger.Fatal(e.Start(":http"))
}
```