package http import ( "context" "net/http" "strconv" "git.ostiwe.com/ostiwe-com/status/model" ) func ExtractLimitOffset(r *http.Request) (int, int, ResponseErrReadyToSend) { limit, offset := r.URL.Query().Get("limit"), r.URL.Query().Get("offset") if limit == "" { limit = "20" } if offset == "" { offset = "0" } limitInt, err := strconv.Atoi(limit) if err != nil { writeErr := NewResponseErrBuilder(). WithMessage("Incorrect limit parameter"). WithDetails(map[string]interface{}{ "err": err.Error(), }). WithStatusCode(http.StatusBadRequest). Ready() return 0, 0, writeErr } offsetInt, err := strconv.Atoi(offset) if err != nil { writeErr := NewResponseErrBuilder(). WithMessage("Incorrect offset parameter"). WithDetails(map[string]interface{}{ "err": err.Error(), }). WithStatusCode(http.StatusBadRequest). Ready() return 0, 0, writeErr } return limitInt, offsetInt, nil } func GetUser(ctx context.Context) *model.User { ctxValue := ctx.Value("user") if ctxValue == nil { return nil } user, ok := ctxValue.(*model.User) if !ok { return nil } return user }