Skip to content
This repository was archived by the owner on Nov 7, 2025. It is now read-only.

Commit 24cb3f4

Browse files
authored
Quesma v2 new frontend (#1057)
This PR is about few things: - moving frontend, backend connectors, processors back to `quesma` module - refactoring to split ingest and search routing - moving some code regarding http frontend and routing and doing some cleanup
1 parent 15f9343 commit 24cb3f4

27 files changed

+1768
-542
lines changed

quesma/v2/frontend_connectors/basic_http_frontend_connector.go renamed to quesma/frontend_connectors/basic_http_frontend_connector.go

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ import (
1414
)
1515

1616
type HTTPRouter struct {
17-
mux *http.ServeMux // Default HTTP multiplexer
18-
handlers map[string]quesma_api.HandlersPipe // Map to store custom route handlers
19-
mutex sync.RWMutex // Mutex for concurrent access to handlers
17+
mux *http.ServeMux // Default HTTP multiplexer
18+
handlers map[string]quesma_api.HandlersPipe // Map to store custom route handlers
19+
fallbackHandler quesma_api.HTTPFrontendHandler
20+
mutex sync.RWMutex // Mutex for concurrent access to handlers
2021
}
2122

2223
func NewHTTPRouter() *HTTPRouter {
@@ -34,13 +35,26 @@ func (router *HTTPRouter) AddRoute(path string, handler quesma_api.HTTPFrontendH
3435
fmt.Printf("Added route: %s\n", path)
3536
}
3637

38+
func (router *HTTPRouter) AddFallbackHandler(handler quesma_api.HTTPFrontendHandler) {
39+
router.mutex.Lock()
40+
defer router.mutex.Unlock()
41+
router.fallbackHandler = handler
42+
}
43+
44+
func (router *HTTPRouter) GetFallbackHandler() quesma_api.HTTPFrontendHandler {
45+
router.mutex.RLock()
46+
defer router.mutex.RUnlock()
47+
return router.fallbackHandler
48+
}
49+
3750
func (router *HTTPRouter) Clone() quesma_api.Cloner {
3851
newRouter := NewHTTPRouter()
3952
router.mutex.Lock()
4053
defer router.mutex.Unlock()
4154
for path, handler := range router.handlers {
4255
newRouter.handlers[path] = handler
4356
}
57+
newRouter.fallbackHandler = router.fallbackHandler
4458
return newRouter
4559
}
4660

@@ -97,15 +111,25 @@ func (h *BasicHTTPFrontendConnector) GetRouter() quesma_api.Router {
97111

98112
func (h *BasicHTTPFrontendConnector) ServeHTTP(w http.ResponseWriter, req *http.Request) {
99113
handlerWrapper, exists := h.router.GetHandlers()[req.URL.Path]
114+
dispatcher := &quesma_api.Dispatcher{}
100115
if !exists {
101-
h.router.Multiplexer().ServeHTTP(w, req)
116+
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
117+
if h.router.GetFallbackHandler() != nil {
118+
fmt.Printf("No handler found for path: %s\n", req.URL.Path)
119+
handler := h.router.GetFallbackHandler()
120+
_, message, _ := handler(req)
121+
_, err := w.Write(message.([]byte))
122+
if err != nil {
123+
fmt.Printf("Error writing response: %s\n", err)
124+
}
125+
}
126+
}).ServeHTTP(w, req)
102127
return
103128
}
104-
dispatcher := &quesma_api.Dispatcher{}
105129
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
106130
metadata, message, _ := handlerWrapper.Handler(req)
107131

108-
metadata, message = dispatcher.Dispatch(handlerWrapper.Processors, metadata, message)
132+
_, message = dispatcher.Dispatch(handlerWrapper.Processors, metadata, message)
109133
_, err := w.Write(message.([]byte))
110134
if err != nil {
111135
fmt.Printf("Error writing response: %s\n", err)

quesma/v2/frontend_connectors/tcp_postgres_connection_handler.go renamed to quesma/frontend_connectors/tcp_postgres_connection_handler.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@ func (p *TcpPostgresConnectionHandler) HandleConnection(conn net.Conn) error {
3232
}
3333
var resp any = msg
3434
metadata := make(map[string]interface{})
35-
metadata, resp = dispatcher.Dispatch(p.processors, metadata, resp)
35+
_, resp = dispatcher.Dispatch(p.processors, metadata, resp)
3636
if resp != nil {
3737
_, err = conn.Write(resp.([]byte))
38+
if err != nil {
39+
return fmt.Errorf("error sending response: %w", err)
40+
}
3841
}
3942
}
4043
}

quesma/go.mod

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ require (
1010
github.com/DataDog/go-sqllexer v0.0.17
1111
github.com/barkimedes/go-deepcopy v0.0.0-20220514131651-17c30cfc62df
1212
github.com/coreos/go-semver v0.3.1
13+
github.com/go-sql-driver/mysql v1.8.1
1314
github.com/goccy/go-json v0.10.3
15+
github.com/google/go-cmp v0.6.0
1416
github.com/google/uuid v1.6.0
1517
github.com/gorilla/mux v1.8.1
1618
github.com/gorilla/securecookie v1.1.2
1719
github.com/gorilla/sessions v1.4.0
1820
github.com/hashicorp/go-multierror v1.1.1
21+
github.com/jackc/pgx/v4 v4.18.3
22+
github.com/jackc/pgx/v5 v5.7.1
1923
github.com/k0kubun/pp v3.0.1+incompatible
2024
github.com/knadh/koanf/parsers/json v0.1.0
2125
github.com/knadh/koanf/parsers/yaml v0.1.0
@@ -34,9 +38,16 @@ require (
3438
)
3539

3640
require (
41+
filippo.io/edwards25519 v1.1.0 // indirect
3742
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
3843
github.com/hashicorp/errwrap v1.0.0 // indirect
39-
github.com/jackc/pgx/v5 v5.7.1 // indirect
44+
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
45+
github.com/jackc/pgconn v1.14.3 // indirect
46+
github.com/jackc/pgio v1.0.0 // indirect
47+
github.com/jackc/pgpassfile v1.0.0 // indirect
48+
github.com/jackc/pgproto3/v2 v2.3.3 // indirect
49+
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
50+
github.com/jackc/pgtype v1.14.0 // indirect
4051
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 // indirect
4152
github.com/knadh/koanf/maps v0.1.1 // indirect
4253
github.com/kr/text v0.2.0 // indirect
@@ -46,6 +57,8 @@ require (
4657
github.com/tidwall/gjson v1.18.0 // indirect
4758
github.com/tidwall/match v1.1.1 // indirect
4859
github.com/tidwall/pretty v1.2.1 // indirect
60+
golang.org/x/crypto v0.28.0 // indirect
61+
golang.org/x/text v0.19.0 // indirect
4962
)
5063

5164
require (

0 commit comments

Comments
 (0)