// Package server implements the HTTP server and RPC dispatch. // Mirrors: odoo/http.py, odoo/service/server.py package server import ( "context" "encoding/json" "fmt" "log" "net/http" "strings" "sync" "time" "github.com/jackc/pgx/v5/pgxpool" "odoo-go/pkg/orm" "odoo-go/pkg/tools" ) // Server is the main Odoo HTTP server. // Mirrors: odoo/service/server.py ThreadedServer type Server struct { config *tools.Config pool *pgxpool.Pool mux *http.ServeMux sessions *SessionStore // xmlTemplateBundle is the JS source for the compiled XML templates, // generated at startup by compileXMLTemplates(). It replaces the // pre-compiled build/js/web/static/src/xml_templates_bundle.js that // was previously produced by tools/compile_templates.py. xmlTemplateBundle string // jsBundle is the concatenated JS bundle built at startup. It contains // all JS files (except module_loader.js) plus the XML template bundle, // served as a single file to avoid hundreds of individual HTTP requests. jsBundle string bus *Bus // Message bus for Discuss long-polling } // New creates a new server instance. func New(cfg *tools.Config, pool *pgxpool.Pool) *Server { s := &Server{ config: cfg, pool: pool, mux: http.NewServeMux(), sessions: NewSessionStore(24*time.Hour, pool), } // Compile XML templates to JS at startup, replacing the Python build step. log.Println("odoo: compiling XML templates...") s.xmlTemplateBundle = compileXMLTemplates(cfg.FrontendDir) // Concatenate all JS files into a single bundle served at /web/assets/bundle.js. // This reduces ~539 individual