pass context as an argument

This commit is contained in:
Carlosokumu 2025-01-06 08:50:53 +03:00
parent 47b5ff0435
commit 974af6b2a7
Signed by: carlos
GPG Key ID: 7BD6BC8160A5C953
6 changed files with 26 additions and 26 deletions

View File

@ -121,9 +121,7 @@ func main() {
} }
defer stateStore.Close() defer stateStore.Close()
rp := &at.ATRequestParser{ rp := &at.ATRequestParser{}
Context: ctx,
}
bsh := handlers.NewBaseSessionHandler(cfg, rs, stateStore, userdataStore, rp, hl) bsh := handlers.NewBaseSessionHandler(cfg, rs, stateStore, userdataStore, rp, hl)
sh := httpserver.NewATSessionHandler(bsh) sh := httpserver.NewATSessionHandler(bsh)

View File

@ -35,7 +35,7 @@ type asyncRequestParser struct {
input []byte input []byte
} }
func (p *asyncRequestParser) GetSessionId(r any) (string, error) { func (p *asyncRequestParser) GetSessionId(ctx context.Context, r any) (string, error) {
return p.sessionId, nil return p.sessionId, nil
} }

View File

@ -6,9 +6,9 @@ import (
"io" "io"
"git.defalsify.org/vise.git/engine" "git.defalsify.org/vise.git/engine"
"git.defalsify.org/vise.git/resource"
"git.defalsify.org/vise.git/persist"
"git.defalsify.org/vise.git/logging" "git.defalsify.org/vise.git/logging"
"git.defalsify.org/vise.git/persist"
"git.defalsify.org/vise.git/resource"
"git.grassecon.net/urdt/ussd/internal/storage" "git.grassecon.net/urdt/ussd/internal/storage"
) )
@ -39,7 +39,7 @@ type RequestSession struct {
// TODO: seems like can remove this. // TODO: seems like can remove this.
type RequestParser interface { type RequestParser interface {
GetSessionId(rq any) (string, error) GetSessionId(context context.Context, rq any) (string, error)
GetInput(rq any) ([]byte, error) GetInput(rq any) ([]byte, error)
} }

View File

@ -1,6 +1,7 @@
package http package http
import ( import (
"context"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
@ -10,7 +11,7 @@ import (
type DefaultRequestParser struct { type DefaultRequestParser struct {
} }
func (rp *DefaultRequestParser) GetSessionId(rq any) (string, error) { func (rp *DefaultRequestParser) GetSessionId(ctx context.Context, rq any) (string, error) {
rqv, ok := rq.(*http.Request) rqv, ok := rq.(*http.Request)
if !ok { if !ok {
return "", handlers.ErrInvalidRequest return "", handlers.ErrInvalidRequest
@ -34,5 +35,3 @@ func (rp *DefaultRequestParser) GetInput(rq any) ([]byte, error) {
} }
return v, nil return v, nil
} }

View File

@ -2,6 +2,7 @@ package http
import ( import (
"bytes" "bytes"
"context"
"errors" "errors"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
@ -161,7 +162,7 @@ func TestDefaultRequestParser_GetSessionId(t *testing.T) {
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
id, err := parser.GetSessionId(tt.request) id, err := parser.GetSessionId(context.Background(),tt.request)
if id != tt.expectedID { if id != tt.expectedID {
t.Errorf("Expected session ID %s, got %s", tt.expectedID, id) t.Errorf("Expected session ID %s, got %s", tt.expectedID, id)

View File

@ -1,12 +1,14 @@
package httpmocks package httpmocks
import "context"
// MockRequestParser implements the handlers.RequestParser interface for testing // MockRequestParser implements the handlers.RequestParser interface for testing
type MockRequestParser struct { type MockRequestParser struct {
GetSessionIdFunc func(any) (string, error) GetSessionIdFunc func(any) (string, error)
GetInputFunc func(any) ([]byte, error) GetInputFunc func(any) ([]byte, error)
} }
func (m *MockRequestParser) GetSessionId(rq any) (string, error) { func (m *MockRequestParser) GetSessionId(ctx context.Context, rq any) (string, error) {
return m.GetSessionIdFunc(rq) return m.GetSessionIdFunc(rq)
} }