Categorygithub.com/SaulDoesCode/transplacer
modulepackage
1.2.0
Repository: https://github.com/sauldoescode/transplacer.git
Documentation: pkg.go.dev

# README

GoDoc

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

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

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"))
}

# Packages

No description provided by the author

# Functions

HTTP2Push initiates an HTTP/2 server push.
Make prepares a new *AssetCache for use.
PrepPath joins a host path with a clean file path.
StringsContainCI reports whether the lists contains a match regardless of its case.

# Variables

AvoidPushing - list of file extentions to skip over when building an http2 push list.
Compressable - list of compressable file types, append to it if needed.
ErrAssetNotFound is for when an asset cannot be located/created.

# Structs

Asset is an http servable resource.
AssetCache is a store for assets.

# Type aliases

HashMap is an alias of cornelk/hashmap.