local-server/cmd/dkl-local-server/kernel.go

36 lines
615 B
Go
Raw Normal View History

2018-06-12 10:09:47 +00:00
package main
import (
2022-07-21 14:03:39 +00:00
"io"
2018-06-12 10:09:47 +00:00
"log"
"net/http"
2022-07-21 14:03:39 +00:00
"os"
2018-06-12 10:09:47 +00:00
)
func renderKernel(w http.ResponseWriter, r *http.Request, ctx *renderContext) error {
2018-12-10 10:59:24 +00:00
path, err := ctx.distFetch("kernels", ctx.Host.Kernel)
2018-06-12 10:09:47 +00:00
if err != nil {
return err
}
2018-12-10 10:59:24 +00:00
log.Printf("sending kernel %s for %q", ctx.Host.Kernel, ctx.Host.Name)
2018-06-12 10:09:47 +00:00
http.ServeFile(w, r, path)
return nil
}
2022-07-21 14:03:39 +00:00
func fetchKernel(out io.Writer, ctx *renderContext) (err error) {
path, err := ctx.distFetch("kernels", ctx.Host.Kernel)
if err != nil {
return err
}
in, err := os.Open(path)
if err != nil {
return
}
defer in.Close()
_, err = io.Copy(out, in)
return
}