lint: fix code style
This commit is contained in:
parent
68c0c63a9f
commit
034c7d5157
@ -26,7 +26,7 @@ func Expose(router gin.IRouter, wrk *worker.Worker) {
|
||||
id, err := wrk.Enqueue(gctx.Request)
|
||||
if err != nil {
|
||||
log.Println("failed to enqueue:", err)
|
||||
gctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
_ = gctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
gctx.Header("X-Correlation-Id", id)
|
||||
@ -87,7 +87,7 @@ func (wh *workerHandler) retry(gctx *gin.Context) {
|
||||
id, err := wh.wrk.Retry(gctx.Request.Context(), requestID)
|
||||
if err != nil {
|
||||
log.Println("failed to retry:", err)
|
||||
gctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
_ = gctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
gctx.Header("X-Correlation-Id", id)
|
||||
@ -106,7 +106,7 @@ func (wh *workerHandler) completeRequest(gctx *gin.Context) {
|
||||
err = wh.wrk.Meta().Complete(requestID)
|
||||
if err != nil {
|
||||
log.Println("failed to mark request as complete:", err)
|
||||
gctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
_ = gctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -154,7 +154,7 @@ func (wh *workerHandler) getAttempt(gctx *gin.Context) {
|
||||
body, err := wh.wrk.Blobs().Get(attempt.ID)
|
||||
if err != nil {
|
||||
log.Println("failed to get body:", err)
|
||||
gctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
_ = gctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
defer body.Close()
|
||||
@ -183,7 +183,7 @@ func (wh *workerHandler) getRequest(gctx *gin.Context) {
|
||||
f, err := wh.wrk.Blobs().Get(requestID)
|
||||
if err != nil {
|
||||
log.Println("failed to get data:", err)
|
||||
gctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
_ = gctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
|
@ -1,6 +1,7 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@ -36,7 +37,7 @@ func (cfg OAuth2) Attach(router gin.IRouter, storage SessionStorage) {
|
||||
|
||||
token, err := cfg.Config.Exchange(gctx.Request.Context(), gctx.Query("code"))
|
||||
if err != nil {
|
||||
gctx.AbortWithError(http.StatusForbidden, err)
|
||||
_ = gctx.AbortWithError(http.StatusForbidden, err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -47,9 +48,9 @@ func (cfg OAuth2) Attach(router gin.IRouter, storage SessionStorage) {
|
||||
|
||||
sessionID := uuid.New().String()
|
||||
session := newOAuthSession(token)
|
||||
err = session.fetchLogin(cfg.ProfileURL, cfg.LoginField)
|
||||
err = session.fetchLogin(gctx.Request.Context(), cfg.ProfileURL, cfg.LoginField)
|
||||
if err != nil {
|
||||
gctx.AbortWithError(http.StatusForbidden, err)
|
||||
_ = gctx.AbortWithError(http.StatusForbidden, err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -86,12 +87,12 @@ func (ss *oauthSession) Valid() bool {
|
||||
return token.Valid()
|
||||
}
|
||||
|
||||
func (ss *oauthSession) GetJSON(url string, response interface{}) error {
|
||||
func (ss *oauthSession) GetJSON(ctx context.Context, url string, response interface{}) error {
|
||||
t, err := ss.token.Token()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -107,9 +108,9 @@ func (ss *oauthSession) GetJSON(url string, response interface{}) error {
|
||||
return json.NewDecoder(res.Body).Decode(response)
|
||||
}
|
||||
|
||||
func (ss *oauthSession) fetchLogin(url string, field string) error {
|
||||
func (ss *oauthSession) fetchLogin(ctx context.Context, url string, field string) error {
|
||||
var profile = make(map[string]interface{})
|
||||
err := ss.GetJSON(url, &profile)
|
||||
err := ss.GetJSON(ctx, url, &profile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ func (ui *uiRouter) unitRequestAttemptResult(gctx *gin.Context) {
|
||||
|
||||
f, err := info.Worker.Blobs().Get(attemptID)
|
||||
if err != nil {
|
||||
gctx.AbortWithError(http.StatusNotFound, err)
|
||||
_ = gctx.AbortWithError(http.StatusNotFound, err)
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
@ -102,10 +102,10 @@ func (ui *uiRouter) unitRequestAttemptInfo(gctx *gin.Context) {
|
||||
gctx.AbortWithStatus(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
requestId := gctx.Param("request")
|
||||
request, err := info.Worker.Meta().Get(requestId)
|
||||
requestID := gctx.Param("request")
|
||||
request, err := info.Worker.Meta().Get(requestID)
|
||||
if err != nil {
|
||||
gctx.AbortWithError(http.StatusNotFound, err)
|
||||
_ = gctx.AbortWithError(http.StatusNotFound, err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -130,7 +130,7 @@ func (ui *uiRouter) unitRequestAttemptInfo(gctx *gin.Context) {
|
||||
baseResponse: base(gctx),
|
||||
unitInfo: info,
|
||||
Request: request,
|
||||
RequestID: requestId,
|
||||
RequestID: requestID,
|
||||
},
|
||||
AttemptID: attemptID,
|
||||
Attempt: attempt,
|
||||
@ -151,10 +151,10 @@ func (ui *uiRouter) unitRequestInfo(gctx *gin.Context) {
|
||||
gctx.AbortWithStatus(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
requestId := gctx.Param("request")
|
||||
request, err := info.Worker.Meta().Get(requestId)
|
||||
requestID := gctx.Param("request")
|
||||
request, err := info.Worker.Meta().Get(requestID)
|
||||
if err != nil {
|
||||
gctx.AbortWithError(http.StatusNotFound, err)
|
||||
_ = gctx.AbortWithError(http.StatusNotFound, err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -162,7 +162,7 @@ func (ui *uiRouter) unitRequestInfo(gctx *gin.Context) {
|
||||
baseResponse: base(gctx),
|
||||
unitInfo: info,
|
||||
Request: request,
|
||||
RequestID: requestId,
|
||||
RequestID: requestID,
|
||||
})
|
||||
}
|
||||
|
||||
@ -178,7 +178,7 @@ func (ui *uiRouter) unitRequestRetry(gctx *gin.Context) {
|
||||
id, err := item.Worker.Retry(gctx.Request.Context(), requestID)
|
||||
if err != nil {
|
||||
log.Println("failed to retry:", err)
|
||||
gctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
_ = gctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -195,14 +195,14 @@ func (ui *uiRouter) unitRequestPayload(gctx *gin.Context) {
|
||||
requestID := gctx.Param("request")
|
||||
info, err := item.Worker.Meta().Get(requestID)
|
||||
if !ok {
|
||||
gctx.AbortWithError(http.StatusNotFound, err)
|
||||
_ = gctx.AbortWithError(http.StatusNotFound, err)
|
||||
return
|
||||
}
|
||||
gctx.Header("Last-Modified", info.CreatedAt.Format(time.RFC850))
|
||||
f, err := item.Worker.Blobs().Get(requestID)
|
||||
if err != nil {
|
||||
log.Println("failed to get data:", err)
|
||||
gctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
_ = gctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
@ -242,15 +242,15 @@ func (ui *uiRouter) unitInvoke(gctx *gin.Context) {
|
||||
return
|
||||
}
|
||||
data := gctx.PostForm("body")
|
||||
req, err := http.NewRequest(http.MethodPost, "/", bytes.NewBufferString(data))
|
||||
req, err := http.NewRequestWithContext(gctx.Request.Context(), http.MethodPost, "/", bytes.NewBufferString(data))
|
||||
if err != nil {
|
||||
gctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
_ = gctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
id, err := info.Worker.Enqueue(req)
|
||||
if err != nil {
|
||||
gctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
_ = gctx.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
gctx.Redirect(http.StatusSeeOther, base(gctx).Rel("/unit", name, "request", id))
|
||||
|
@ -482,19 +482,20 @@ func (mgr *Worker) restoreRequest(ctx context.Context, requestID string, info *m
|
||||
return req, nil
|
||||
}
|
||||
|
||||
func encodeID(nsId byte, id uint64) string {
|
||||
func encodeID(nsID byte, id uint64) string {
|
||||
var data [9]byte
|
||||
data[0] = nsId
|
||||
data[0] = nsID
|
||||
binary.BigEndian.PutUint64(data[1:], id)
|
||||
return strings.ToUpper(hex.EncodeToString(data[:]))
|
||||
}
|
||||
|
||||
func decodeID(val string) (byte, uint64, error) {
|
||||
const idLen = 1 + 8
|
||||
hx, err := hex.DecodeString(val)
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
if len(hx) != 9 {
|
||||
if len(hx) != idLen {
|
||||
return 0, 0, errors.New("too short")
|
||||
}
|
||||
n := binary.BigEndian.Uint64(hx[1:])
|
||||
|
Loading…
x
Reference in New Issue
Block a user