Skip to content

cjtoolkit/zipfs

Repository files navigation

GoDoc

ZipFS for net/http

Installation

$ go get github.com/cjtoolkit/zipfs

Example

package main

import (
	"fmt"
	"log"
	"net/http"

	"github.com/cjtoolkit/zipfs"
)

func main() {
	// Init ZipFS, if the zip file does not exist it will fallback to embedded zip file within application, if that
	// also does not exist, it will panic.
	fs := zipfs.InitZipFs("asset.zip")

	fmt.Println("Running ZipFS via http server on port 8080.")
	log.Print(http.ListenAndServe(":8080", http.FileServer(fs)))
}

To embed zip to the application, first create a zip file with your preferred achiever with compression disabled. Than append the content of the zip file to the compiled application. You can use this simple shell command to append.

$ cat asset.zip >> application

Credit

This project is based on the work of the following: