48 lines
822 B
Go
48 lines
822 B
Go
package common
|
|
|
|
import "os"
|
|
|
|
|
|
type Request struct {
|
|
Type string
|
|
Data interface{}
|
|
|
|
PrjGit string
|
|
}
|
|
|
|
type RequestHandler struct {
|
|
ObsToken, GiteaToken string
|
|
|
|
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
|
|
}
|
|
|