Skip to content
Snippets Groups Projects
Select Git revision
  • f93400da9227f071ec61fca13d6af9a2d7d2cc4a
  • master default protected
  • renovate/golang.org-x-net-0.x
  • renovate/golang.org-x-crypto-0.x
  • renovate/go-1.x
  • renovate/golang.org-x-sync-0.x
  • renovate/github.com-protonmail-gopenpgp-v3-3.x
  • renovate/github.com-pquerna-otp-1.x
  • renovate/github.com-go-ldap-ldap-v3-3.x
  • renovate/github.com-prometheus-client_golang-1.x
  • renovate/git.autistici.org-id-auth-digest
  • renovate/github.com-protonmail-gopenpgp-v2-2.x
  • better-validation
13 results

actions_resource.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))
    }