debian-forge-composer/cmd/osbuild-worker-executor/handler_result.go
Sanne Raymaekers b0543e89f4 osbuild-worker-executor: fix lint warnings/errors
The osbuild-composer linting found a bunch of issues that this
commit fixes.
2024-06-05 18:26:08 +02:00

45 lines
1.1 KiB
Go

package main
import (
"io"
"net/http"
"os"
"path/filepath"
"github.com/sirupsen/logrus"
)
func handleResult(logger *logrus.Logger, config *Config) http.Handler {
return http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
logger.Debugf("handlerResult called on %s", r.URL.Path)
if r.Method != http.MethodGet {
http.Error(w, "result endpoint only supports Get", http.StatusMethodNotAllowed)
return
}
buildResult := newBuildResult(config)
switch {
case buildResult.Bad():
http.Error(w, "build failed", http.StatusBadRequest)
f, err := os.Open(filepath.Join(config.BuildDirBase, "build/build.log"))
if err != nil {
logger.Errorf("cannot open log: %v", err)
return
}
defer f.Close()
if _, err := io.Copy(w, f); err != nil {
logger.Errorf("Unable to write log to response")
}
return
case buildResult.Good():
// good result
default:
http.Error(w, "build still running", http.StatusTooEarly)
return
}
fss := http.FileServer(http.Dir(filepath.Join(config.BuildDirBase, "build/output")))
fss.ServeHTTP(w, r)
},
)
}