49 lines
856 B
Go
49 lines
856 B
Go
package common
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
)
|
|
|
|
|
|
type Request struct {
|
|
Type string
|
|
Data interface{}
|
|
|
|
PrjGit string
|
|
}
|
|
|
|
type RequestHandler struct {
|
|
Error error
|
|
GitCommiter, GitPath string
|
|
Branch []string
|
|
|
|
StdLogger, ErrLogger *log.Logger
|
|
Request
|
|
}
|
|
|
|
func (r *RequestHandler) WriteError() {
|
|
r.ErrLogger.Println("internal error sent")
|
|
}
|
|
|
|
|
|
func CreateRequestHandler(git_author, name string) *RequestHandler {
|
|
var h *RequestHandler = new(RequestHandler)
|
|
|
|
h.StdLogger, h.ErrLogger = CreateStdoutLogger(os.Stdout, os.Stderr)
|
|
|
|
h.GitCommiter = git_author
|
|
h.GitPath, h.Error = os.MkdirTemp("", name)
|
|
if h.Error != nil {
|
|
h.ErrLogger.Printf("Cannot create temp dir: %v\n", h.Error)
|
|
return h
|
|
}
|
|
|
|
if h.Error = os.Chmod(h.GitPath, 0700); h.Error != nil {
|
|
h.ErrLogger.Printf("Cannot fix permissions of temp dir: %v\n", h.Error)
|
|
return h
|
|
}
|
|
return h
|
|
}
|
|
|