Skip to content
Snippets Groups Projects
Select Git revision
  • 58b071b836f94e5e1567499b0edc651875f59f9b
  • master default
  • renovate/golang.org-x-crypto-0.x
  • renovate/go-1.x
  • renovate/golang.org-x-sync-0.x
  • renovate/opentelemetry-go-monorepo
  • renovate/github.com-go-webauthn-webauthn-0.x
  • renovate/github.com-mattn-go-sqlite3-1.x
  • renovate/github.com-go-ldap-ldap-v3-3.x
  • renovate/github.com-prometheus-client_golang-1.x
  • renovate/github.com-google-go-cmp-0.x
  • renovate/github.com-lunixbochs-struc-digest
  • renovate/github.com-duo-labs-webauthn-digest
13 results

main.go

Blame
  • static.go 788 B
    package httputil
    
    import (
    	"bytes"
    	"io/ioutil"
    	"net/http"
    	"os"
    	"time"
    )
    
    // StaticContent is an http.Handler that serves in-memory data as if
    // it were a static file.
    type StaticContent struct {
    	modtime time.Time
    	name    string
    	data    []byte
    }
    
    // LoadStaticContent creates a StaticContent by loading data from a file.
    func LoadStaticContent(path string) (*StaticContent, error) {
    	stat, err := os.Stat(path)
    	if err != nil {
    		return nil, err
    	}
    	data, err := ioutil.ReadFile(path) // #nosec
    	if err != nil {
    		return nil, err
    	}
    	return &StaticContent{
    		name:    path,
    		modtime: stat.ModTime(),
    		data:    data,
    	}, nil
    }
    
    func (c *StaticContent) ServeHTTP(w http.ResponseWriter, req *http.Request) {
    	http.ServeContent(w, req, c.name, c.modtime, bytes.NewReader(c.data))
    }