autogits/bots-common/request_handler.go

49 lines
856 B
Go
Raw Normal View History

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