// Static returns a middleware handler that serves static files in the given directory.
549609
func Static(asset func(string) ([]byte, error), options ...Options) gin.HandlerFunc {
	if asset == nil {
		panic("asset is nil")
	}

	opt := Options{}
	for _, o := range options {
		opt = o
		break
	}
	opt.init()

	modtime := time.Now()

	return func(c *gin.Context) {
		if c.Request.Method != "GET" && c.Request.Method != "HEAD" {
			// Request is not correct. Go farther.
			return
		}

		url := c.Request.URL.Path
		if !strings.HasPrefix(url, opt.Dir) {
			return
		}
		file := strings.TrimPrefix(
			strings.TrimPrefix(url, opt.Dir),
			"/",
		)
		b, err := asset(file)

		if err != nil {
			// Try to serve the index file.
			b, err = asset(path.Join(file, opt.IndexFile))

			if err != nil {
				// Go farther if the asset could not be found.
				return
			}
		}

		if !opt.SkipLogging {
			log.Println("[Static] Serving " + url)
		}

		http.ServeContent(c.Writer, c.Request, url, modtime, bytes.NewReader(b))
		c.Abort()
	}
}
761530
func NewStatic(dir string) *Static {
	directory := http.Dir(dir)
	return &Static{
		Dir:       directory,
		Prefix:    "",
		IndexFile: "index.html",
	}
}
853551
func (h *guiHandler) serveStatic(w http.ResponseWriter, req *http.Request) {
	logger.Debugf("serving Juju GUI static files")
	staticDir := filepath.Join(h.rootDir, "static")
	fs := http.FileServer(http.Dir(staticDir))
	http.StripPrefix(h.hashedPath("static/"), fs).ServeHTTP(w, req)
}
613377
func (_m *Router) StaticFiles(path string, fs http.Handler) {
	_m.Called(path, fs)
}
355603
func StaticFieldFromInstance(val reflect.Value, t reflect.Type, fieldNo int, name string) *Field {
	ret := StaticField(name, fmt.Sprintf("%s", val.Field(fieldNo).Interface()))
	return ret
}
828198
func serve(baseDirectoryPath string, fnR AdaptRouter, fnT TemplateData) (ln net.Listener) {
	// Init router
	var r = httprouter.New()

	// Static files
	r.ServeFiles("/static/*filepath", http.Dir(filepath.Join(baseDirectoryPath, "resources", "static")))

	// Dynamic pages
	r.GET("/templates/*page", handleTemplates(fnT))

	// Adapt router
	if fnR != nil {
		fnR(r)
	}

	// Parse templates
	var err error
	if templates, err = astitemplate.ParseDirectory(filepath.Join(baseDirectoryPath, "resources", "templates"), ".html"); err != nil {
		astilog.Fatal(err)
	}

	// Listen
	if ln, err = net.Listen("tcp", "127.0.0.1:"); err != nil {
		astilog.Fatal(err)
	}
	astilog.Debugf("Listening on %s", ln.Addr())

	// Serve
	go http.Serve(ln, r)
	return
}
1079510
func (ctr *rowConstructor) Static(width ...int) {
	for i := range width {
		width[i] = ctr.win.ctx.scale(width[i])
	}

	ctr.StaticScaled(width...)
}
506364
func StaticService(host string, port int) Service {
	return &svcVals{host: host, port: port}
}
1355106
func StaticFileHandler(path string) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		http.ServeFile(w, r, path)
	}
}
644051
func StaticFileHandler(filename string) http.Handler {
	fcontents, err := ioutil.ReadFile(filename) // cache the contents of the file, this is the difference from net/http's impl, this is used only for static files, like favicons, css and so on
	if err != nil {
		return errorHandler(http.StatusBadRequest)
	}
	return StaticContentHandler(fcontents, TypeByExtension(filename))
}
765512
func (ss *StaticServer) DirectoryHandler(prefix, dirName string) http.Handler {
	if !strings.HasSuffix(prefix, "/") {
		prefix += "/"
	}
	idBase := dirName
	dirName = ss.resolve(dirName)
	return &staticHandler{
		ss: ss,
		id: func(p string) string {
			if !strings.HasPrefix(p, prefix) {
				return "."
			}
			return path.Join(idBase, p[len(prefix):])
		},
		open: func(p string) (io.ReadCloser, int64, string, error) {
			if !strings.HasPrefix(p, prefix) {
				return nil, 0, "", errors.New("request url does not match directory prefix")
			}
			p = p[len(prefix):]
			return ss.openFile(filepath.Join(dirName, filepath.FromSlash(p)))
		},
	}
}
597566
func (d *DebugAssets) Handler() http.Handler {
	return http.FileServer(NewDir(d.Dir, d.Default))
}
265800
func (sf StaticFile) AsStaticFIFO() (fifo StaticFIFO, ok bool) {
	if sf.b.ss.Type == "fifo" {
		return StaticFIFO{sf}, true
	}

	return
}
1061500
func NewStatic(urlPrefix string, manifestPath string, options ...optionSetter) (*Static, error) {
	if !strings.HasSuffix(urlPrefix, "/") {
		urlPrefix += "/"
	}
	static := &Static{
		urlPrefix:      urlPrefix,
		manifestPath:   manifestPath,
		manifestLoader: ioutil.ReadFile,
	}
	for _, optionSetter := range options {
		optionSetter(static)
	}
	if static.mappingBuilder == nil {
		static.mappingBuilder = func() (StaticMapper, error) {
			return createMapping(static.manifestLoader, manifestPath, static.useMinified)
		}
	}
	mapping, err := static.mappingBuilder()
	if err != nil {
		return nil, err
	}
	static.mapping = mapping
	return static, nil
}
694638
func main() {
	staticFields := make(map[string]interface{})
	staticFields["foo"] = "bar"
	baseDir := ""

	if wd, err := os.Getwd(); err != nil {
		log.Fatal(err)
	} else {
		baseDir = wd
	}

	config := bunyan.Config{
		Name: "app",
		Streams: []bunyan.Stream{
			{
				Stream: os.Stdout,
			},
			{
				Path:  filepath.Join(baseDir, "info.log"),
				Level: bunyan.LogLevelInfo,
			},
			{
				Path:  filepath.Join(baseDir, "error.log"),
				Level: bunyan.LogLevelError,
			},
		},
		StaticFields: staticFields,
	}

	if l, err := bunyan.CreateLogger(config); err != nil {
		log.Fatal(err)
	} else {
		chStatic := make(map[string]interface{})
		chStatic["baz"] = "stuff"
		c := l.Child(chStatic)

		l.Info("i am the parent %d", 100)
		c.Info("i am the child")
		l.Error(errors.New("oh no!!!"), "what happened %s", "???")
	}
}
604293
func (r *Router) Static(pattern string, dir string) {
	//append a regex to the param to match everything
	// that comes after the prefix
	pattern = pattern + "(.+)"
	r.Get(pattern, func(w http.ResponseWriter, req *http.Request) {
		path := filepath.Clean(req.URL.Path)
		path = filepath.Join(dir, path)
		http.ServeFile(w, req, path)
	})
}
1357677
func (r *router) StaticRoot(fs http.Handler) {
	r.router.NotFound = r.group.chain.Then(fs)
}