Giter Site home page Giter Site logo

murlocx102 / esc Goto Github PK

View Code? Open in Web Editor NEW

This project forked from maddyblue/esc

0.0 1.0 0.0 1.45 MB

A simple file embedder for Go

Home Page: http://godoc.org/github.com/mjibson/esc

License: MIT License

Go 54.33% CSS 27.78% JavaScript 5.82% HTML 12.07%

esc's Introduction

esc

GoDoc

esc embeds files into go programs and provides http.FileSystem interfaces to them.

It adds all named files or files recursively under named directories at the path specified. The output file provides an http.FileSystem interface with zero dependencies on packages outside the standard library.

Installation

go get -u github.com/mjibson/esc

Usage

esc [flag] [name ...]

The flags are:

-o=""
	output filename, defaults to stdout
-pkg="main"
	package name of output file, defaults to main
-prefix=""
	strip given prefix from filenames
-ignore=""
	regular expression for files to ignore
-include=""
	regular expression for files to include
-modtime=""
	Unix timestamp to override as modification time for all files
-private
	unexport functions by prefixing them with esc, e.g. FS -> escFS
-no-compress
	do not compress files

Accessing Embedded Files

After producing an output file, the assets may be accessed with the FS() function, which takes a flag to use local assets instead (for local development).

  • (_esc)?FS(Must)?(Byte|String) returns an asset as a (byte slice|string).
  • (_esc)?FSMust(Byte|String) panics if the asset is not found.

Go Generate

esc can be invoked by go generate:

//go:generate esc -o static.go -pkg server static

Example

Embedded assets can be served with HTTP using the http.FileServer. Assuming you have a directory structure similar to the following:

.
├── main.go
└── static
    ├── css
    │   └── style.css
    └── index.html

Where main.go contains:

package main

import (
	"log"
	"net/http"
)

func main() {
	// FS() is created by esc and returns a http.Filesystem.
	http.Handle("/static/", http.FileServer(FS(false)))
	log.Fatal(http.ListenAndServe(":8080", nil))
}

  1. Generate the embedded data: esc -o static.go static
  2. Start the server: go run main.go static.go
  3. Access http://localhost:8080/static/index.html to view the files.

You can see worked example in example dir just run it as go run example/main.go example/static.go

esc's People

Contributors

maddyblue avatar vkryukov avatar warmans avatar mekegi avatar jonboulle avatar martint17r avatar mweagle avatar maxatome avatar simonrichardson avatar terryh avatar msample avatar slavikm avatar syscrusher avatar 2sidedfigure avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.