• Stars
    star
    871
  • Rank 52,374 (Top 2 %)
  • Language
    Go
  • License
    BSD 2-Clause "Sim...
  • Created over 10 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Serves embedded files from `jteeuwen/go-bindata` with `net/http`

go-bindata-assetfs

Serve embedded files from go-bindata with net/http.

GoDoc

Installation

Install with

$ go get github.com/go-bindata/go-bindata/...
$ go get github.com/elazarl/go-bindata-assetfs/...

Creating embedded data

Usage is identical to go-bindata usage, instead of running go-bindata run go-bindata-assetfs.

The tool will create a bindata_assetfs.go file, which contains the embedded data.

A typical use case is

$ go-bindata-assetfs data/...

Using assetFS in your code

The generated file provides an assetFS() function that returns a http.Filesystem wrapping the embedded files. What you usually want to do is:

http.Handle("/", http.FileServer(assetFS()))

This would run an HTTP server serving the embedded files.

Without running binary tool

You can always just run the go-bindata tool, and then

use

import "github.com/elazarl/go-bindata-assetfs"
...
http.Handle("/",
http.FileServer(
&assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir, AssetInfo: AssetInfo, Prefix: "data"}))

to serve files embedded from the data directory.

SPA applications

For single page applications you can use Fallback: "index.html" in AssetFS context, so if route doesn't match the pattern it will fallback to file specified.

example

import "github.com/elazarl/go-bindata-assetfs"
...
http.Handle("/",
http.FileServer(
&assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir, AssetInfo: AssetInfo, Prefix: "data", Fallback: "index.html"}))

More Repositories

1

goproxy

An HTTP proxy library for Go
Go
5,980
star
2

gosloppy

Run and test Go code with unused imports and variables
Go
53
star
3

10kthreads

Show that handling 10k threads with thread per connection is possible
C
24
star
4

cpu_affinity

A small C library to set CPU affinity for threads portably
HTML
21
star
5

go-java

Go runtime implementation in Java
Java
18
star
6

hadoop_rpc_walktrhough

What happens on the wire when Hadoop RPC call is issued?
Go
14
star
7

hadoophelpers

Collection of helper utilities for hadoop
Go
8
star
8

RangeTree

An implementation of Range Tree with fractional cascading
Java
6
star
9

customize_tinycorelinux

Scripts to easily customize a tinycorelinux ISO
Shell
5
star
10

goproxy2

Experimental branch of goproxy, UNSTABLE! WILL BREAK!
Go
4
star
11

qemu-with-bridge

Create a local bridge, NAT it through default GW, runs QEMU with netdev bridged
Python
4
star
12

goblkid

reimplementation of libblkid in Go
Go
3
star
13

vnccheckbsod

Checks if a VM has BSOD by analyzing screenshot from VNC
Go
3
star
14

javaUnicodePitfalls

Examples of Unicode pitfalls in Java.
Java
3
star
15

multireducers

Run multiple logical mapreduce jobs on the same physical mapreduce job
Java
3
star
16

use_method_talk

code to demonstrate bottlenecks solvable by USE methodology
Shell
2
star
17

runCGI

Executes a CGI script using parameters from a .yaml file
C++
2
star
18

tup

The best build tool in the world
C
2
star
19

gueststack

Experiment how to sample KVM guest stack
Perl
2
star
20

addr2line

go library runs addr2line in background and query it
Go
1
star
21

serstl

serialize and deserialize STL containers to standard streams
C
1
star
22

nopOS

An OSv-based operating system that does absolutely nothing
C
1
star
23

EmptyJavaSSL

Example of an empty SSL socket connection which causes an exception to be throw
Java
1
star
24

elazarl.github.io

Short text blurbs about technology
HTML
1
star
25

ident-for-cpp

Force a string to be included in an executable
C++
1
star