autogits/bots-common/request_handler.go

46 lines
792 B
Go
Raw Normal View History

2024-07-07 21:08:41 +02:00
package common
import "os"
type Request struct {
Type string
Data interface{}
PrjGit string
}
type RequestHandler struct {
Error error
GitCommiter, GitPath string
Branch []string
Logger
Request
}
func (r *RequestHandler) WriteError() {
r.LogError("%s", "internal error sent")
}
func CreateRequestHandler(git_author, name string) *RequestHandler {
var h *RequestHandler = new(RequestHandler)
h.Logger = CreateStdoutLogger(os.Stdout, os.Stderr)
h.GitCommiter = git_author
h.GitPath, h.Error = os.MkdirTemp("", name)
if h.Error != nil {
h.Logger.LogError("Cannot create temp dir: %v", h.Error)
return h
}
if h.Error = os.Chmod(h.GitPath, 0700); h.Error != nil {
h.Logger.LogError("Cannot fix permissions of temp dir: %v", h.Error)
return h
}
return h
}