first compiling version

This commit is contained in:
ston1th 2023-03-15 01:51:45 +01:00
commit 3d54199faa
27 changed files with 908 additions and 243 deletions

View file

@ -58,13 +58,19 @@ func (a *Approver) Status(id, aid string) (s Status) {
s = app.Status
}
a.mu.RUnlock()
if s == Rejected {
a.mu.Lock()
delete(a.m, aid)
a.mu.Unlock()
}
return
}
func (a *Approver) Update(aid string, s Status) {
a.mu.Lock()
if _, ok := a.m[aid]; ok {
a.m[aid].Status = s
if app, ok := a.m[aid]; ok {
app.Status = s
a.m[aid] = app
}
a.mu.Unlock()
}
@ -95,9 +101,3 @@ func (s Status) String() string {
}
return "[invalid]"
}
type Route struct {
Path string
Handler CtxHandler
Methods []string
}

View file

@ -15,7 +15,8 @@ import (
)
type ContextData struct {
DB *db.DB
DB *db.DB
Approver *Approver
}
func NewContext(w http.ResponseWriter, r *http.Request, data *ContextData, log logr.Logger) *Context {

View file

@ -11,13 +11,13 @@ import (
type Error interface {
Error() string
JSON() string
Status() int
Code() int
}
// Err implements the Error interface
type Err struct {
err string
status int
err string
code int
}
// Error returns the error string
@ -27,29 +27,31 @@ func (a Err) Error() string {
// Error returns the error string as JSON format
func (a Err) JSON() string {
return `{"error":"` + a.err + `","status":` + strconv.Itoa(a.status) + `}`
return `{"error":"` + a.err + `","code":` + strconv.Itoa(a.code) + `}`
}
// Status returns the HTTP status code
func (a Err) Status() int {
return a.status
// Code returns the HTTP status code
func (a Err) Code() int {
return a.code
}
func newError(err string, status int) Error {
func newError(err string, code int) Error {
return Err{
err: err,
status: status,
err: err,
code: code,
}
}
var (
ErrInvalidAPIRoute = newError("invalid api route", http.StatusNotFound)
ErrBadreq = newError("bad request", http.StatusBadRequest)
ErrForbidden = newError("forbidden", http.StatusForbidden)
ErrNotFound = newError("not found", http.StatusNotFound)
ErrKeyNotFound = newError("key not found", http.StatusNotFound)
ErrReqNotFound = newError("key request not found", http.StatusNotFound)
ErrTooManyApprovals = newError("too many approvals pending", http.StatusConflict)
ErrMNA = newError("method not allowed", http.StatusMethodNotAllowed)
ErrISE = newError("internal server error", http.StatusInternalServerError)
ErrInvalidAPIRoute = newError("invalid api route", http.StatusNotFound)
ErrInvalid = newError("invalid data", http.StatusBadRequest)
ErrBadreq = newError("bad request", http.StatusBadRequest)
ErrForbidden = newError("forbidden", http.StatusForbidden)
ErrNotFound = newError("not found", http.StatusNotFound)
ErrKeyNotFound = newError("key not found", http.StatusNotFound)
ErrReqNotFound = newError("key request not found", http.StatusNotFound)
ErrTooManyApprovals = newError("too many approvals pending", http.StatusConflict)
ErrKeyRequestRejected = newError("key request rejected", http.StatusConflict)
ErrMNA = newError("method not allowed", http.StatusMethodNotAllowed)
ErrISE = newError("internal server error", http.StatusInternalServerError)
)