Skip to content

feat: migrate backend from beego to gin#335

Open
vishalm0509 wants to merge 143 commits intostagingfrom
feat/gin
Open

feat: migrate backend from beego to gin#335
vishalm0509 wants to merge 143 commits intostagingfrom
feat/gin

Conversation

@vishalm0509
Copy link
Copy Markdown
Collaborator

Description

  • Replaced Beego HTTP stack with Gin across handlers, routing, middleware, and server startup while keeping the existing API contract and file structure.
  • Migrated ORM layer from Beego ORM to GORM, including DB initialization, model/query rewrites, and runtime automigration with existing schema compatibility.

Fixes # (issue)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • [] New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Scenario A
  • Scenario B

Screenshots or Recordings

Related PR's (If Any):

badalprasadsingh and others added 13 commits March 2, 2026 18:12
Signed-off-by: badalprasadsingh <badal@datazip.io>
Signed-off-by: badalprasadsingh <badal@datazip.io>
Signed-off-by: badalprasadsingh <badal@datazip.io>
Signed-off-by: badalprasadsingh <badal@datazip.io>
Signed-off-by: badalprasadsingh <badal@datazip.io>
Signed-off-by: badalprasadsingh <badal@datazip.io>
@vishalm0509 vishalm0509 changed the title feat: migrate from beego to gin feat: migrate backend from beego to gin Mar 9, 2026
Signed-off-by: badalprasadsingh <badal@datazip.io>
@vishalm0509 vishalm0509 changed the base branch from master to staging March 9, 2026 18:33
@vishalm0509 vishalm0509 marked this pull request as ready for review March 9, 2026 21:15
vishalm0509 and others added 5 commits March 10, 2026 03:35
Signed-off-by: badalprasadsingh <badal@datazip.io>
Signed-off-by: badalprasadsingh <badal@datazip.io>
Signed-off-by: badalprasadsingh <badal@datazip.io>
if err != nil || value == "" {
panic("Required config variable not found: ," + v)
func checkForRequiredVariables() {
cfg := appconfig.Load()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Init() calls appconfig.Load() at line 117 and checkForRequiredVariables() also calls here, pass cfg in the function

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Config is loaded once at startup and then every time we call appconfig.Load() it returns the already loaded config. Therefore, no re-computation of all the envs.

// this loads first on startup
var cfg = loadConfig()

// this serves the already loaded cfg
func Load() Config {
	return cfg
}

gormlogger "gorm.io/gorm/logger"

"github.com/datazip-inc/olake-ui/server/internal/constants"
"github.com/datazip-inc/olake-ui/server/internal/appconfig"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how can we avoid import of appconfig in multiple packages

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Config is loaded once at startup and then every time we call appconfig.Load() it returns the already loaded config. Therefore, no re-computation of all the envs.

// this loads first on startup
var cfg = loadConfig()

// this serves the already loaded cfg
func Load() Config {
	return cfg
}

It is similar to that of web.AppConfig.String(constants.ConfOLakePostgresUser) we import web everywhere. appconfig is similar to that

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we think of any alternate to avoid this now

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have decided to use this now

)

// ValidateStruct validates any struct that has `validate` tags.
func Validate(s interface{}) error {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't we require this anymore?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, here c.ShouldBindJSON() handles bindings.

func bindAndValidate(c *gin.Context, target interface{}) error {
	return c.ShouldBindJSON(target)
}

We have replaced Username string json:"username" validate:"required" example:"admin" (validate) with this (binding) which does the same work.

SessionData string `json:"session_data" orm:"column(session_data);type(text)"`
SessionExpiry time.Time `json:"session_expiry" orm:"column(session_expiry)"`
SessionKey string `json:"session_key" gorm:"column:session_key;primaryKey;size:64"`
SessionData []byte `json:"session_data" gorm:"column:session_data;type:bytea"`
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why? Session.SessionData TEXT -> BYTEA

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the earlier code beego also wrote data to postgres in []byte

	// Add session table if sessions are enabled
	if web.BConfig.WebConfig.Session.SessionOn {
		_, err = orm.NewOrm().Raw(`CREATE TABLE IF NOT EXISTS session (
    session_key VARCHAR(64) PRIMARY KEY,
    session_data BYTEA,
    session_expiry TIMESTAMP WITH TIME ZONE
);`).Exec()
Screenshot 2026-03-12 at 12 57 21

BaseModel
ID int `json:"id" gorm:"column:id;primaryKey;autoIncrement"`
Name string `json:"name" gorm:"column:name;size:100"`
SourceID int `json:"source_id" gorm:"column:source_id"`
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

won't it cause any issue changing *Source -> int

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is FK reference ID, we still can access the Source object with preLoad

	Source      *Source      `json:"source,omitempty" gorm:"foreignKey:SourceID;references:ID"`
	Destination *Destination `json:"destination,omitempty" gorm:"foreignKey:DestID;references:ID"`
	CreatedBy   *User        `json:"created_by,omitempty" gorm:"foreignKey:CreatedByID;references:ID"`
	UpdatedBy   *User        `json:"updated_by,omitempty" gorm:"foreignKey:UpdatedByID;references:ID"`

Comment thread server/internal/handlers/auth.go Outdated
// @Router /signup [post]
func (h *Handler) Signup() {
func (h *Handler) Signup(c *gin.Context) {
var req models.User
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we create dto's for these as well?

Comment thread server/internal/handlers/destination.go Outdated
return
}
utils.SuccessResponse(&h.Controller, "Destinations listed successfully", items)
successResponse(c, "Destinations listed successfully", items)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
successResponse(c, "Destinations listed successfully", items)
successResponse(c, "destinations listed successfully", items)

return
}

if req.Source.ID == nil {
if err := dto.ValidateSourceType(req.Source.Type); err != nil {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't we require source type validation anymore?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NEeded

utils.ErrorResponse(&h.Controller, http.StatusBadRequest, fmt.Sprintf("failed to validate request: %s", err), err)
return
}
if req.Source.Name == "" || req.Source.Version == "" || req.Source.Config == "" {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't we require this check anymore?

h.Ctx.Output.Header("Access-Control-Expose-Headers", "Content-Disposition")

if err := h.etl.StreamLogArchive(id, filePath, h.Ctx.ResponseWriter); err != nil {
logger.Errorf("failed to stream log archive job_id[%d]: %s", id, err)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add this back

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Signed-off-by: badalprasadsingh <badal@datazip.io>
Signed-off-by: badalprasadsingh <badal@datazip.io>
Signed-off-by: badalprasadsingh <badal@datazip.io>
Signed-off-by: badalprasadsingh <badal@datazip.io>
vishalm0509 and others added 2 commits April 6, 2026 14:37
* initial commit

Signed-off-by: badalprasadsingh <badal@datazip.io>

* lint fix

Signed-off-by: badalprasadsingh <badal@datazip.io>

* major backend APIs for fusion

Signed-off-by: badalprasadsingh <badal@datazip.io>

* refactor: domain-driver level

Signed-off-by: badalprasadsingh <badal@datazip.io>

* major refactoring

Signed-off-by: badalprasadsingh <badal@datazip.io>

* chore: services and add cancel api

Signed-off-by: badalprasadsingh <badal@datazip.io>

* fix: cron

Signed-off-by: badalprasadsingh <badal@datazip.io>

* add go.sum

Signed-off-by: badalprasadsingh <badal@datazip.io>

* minor lint fixes

Signed-off-by: badalprasadsingh <badal@datazip.io>

* fix: compaction.go

Signed-off-by: badalprasadsingh <badal@datazip.io>

* minor lint

Signed-off-by: badalprasadsingh <badal@datazip.io>

* add compaction enable

Signed-off-by: badalprasadsingh <badal@datazip.io>

* fix: minor

Signed-off-by: badalprasadsingh <badal@datazip.io>

* sort databases and catalogs

Signed-off-by: badalprasadsingh <badal@datazip.io>

* minor

Signed-off-by: badalprasadsingh <badal@datazip.io>

* fix: minor

Signed-off-by: badalprasadsingh <badal@datazip.io>

* removed unceessary dependencies

Signed-off-by: badalprasadsingh <badal@datazip.io>

* minor

Signed-off-by: badalprasadsingh <badal@datazip.io>

* minor

Signed-off-by: badalprasadsingh <badal@datazip.io>

* fix: minor

Signed-off-by: badalprasadsingh <badal@datazip.io>

* major refactoring

Signed-off-by: badalprasadsingh <badal@datazip.io>

* fix: remove OptimizerGroup from constants

Signed-off-by: badalprasadsingh <badal@datazip.io>

* minor

Signed-off-by: badalprasadsingh <badal@datazip.io>

* minor

Signed-off-by: badalprasadsingh <badal@datazip.io>

* minor

Signed-off-by: badalprasadsingh <badal@datazip.io>

* minor

Signed-off-by: badalprasadsingh <badal@datazip.io>

* minor

Signed-off-by: badalprasadsingh <badal@datazip.io>

* optimisation -> optimization

Signed-off-by: badalprasadsingh <badal@datazip.io>

* optimisation -> optimization

Signed-off-by: badalprasadsingh <badal@datazip.io>

* minor

Signed-off-by: badalprasadsingh <badal@datazip.io>

* refresh token logic

Signed-off-by: badalprasadsingh <badal@datazip.io>

* update piggy backing to add sep download logic

Signed-off-by: badalprasadsingh <badal@datazip.io>

* review changes

Signed-off-by: badalprasadsingh <badal@datazip.io>

* minor change

Signed-off-by: badalprasadsingh <badal@datazip.io>

* minor change

Signed-off-by: badalprasadsingh <badal@datazip.io>

* minor change

Signed-off-by: badalprasadsingh <badal@datazip.io>

* minor change

Signed-off-by: badalprasadsingh <badal@datazip.io>

* minor change

Signed-off-by: badalprasadsingh <badal@datazip.io>

* minor change

Signed-off-by: badalprasadsingh <badal@datazip.io>

* minor todi

Signed-off-by: badalprasadsingh <badal@datazip.io>

* adding todo for camel case

Signed-off-by: badalprasadsingh <badal@datazip.io>

* adding todo for camel or snake case

Signed-off-by: badalprasadsingh <badal@datazip.io>

* fix: minor

Signed-off-by: badalprasadsingh <badal@datazip.io>

* apply insert filter on all apis

Signed-off-by: badalprasadsingh <badal@datazip.io>

* chore: cleanup

* import feature

Signed-off-by: badalprasadsingh <badal@datazip.io>

* minor

Signed-off-by: badalprasadsingh <badal@datazip.io>

* feat(optimization): import destination as catalog in opt (#343)

* import feature

Signed-off-by: badalprasadsingh <badal@datazip.io>

* minor

Signed-off-by: badalprasadsingh <badal@datazip.io>

---------

Signed-off-by: badalprasadsingh <badal@datazip.io>
Co-authored-by: Ankit Sharma <111491139+hash-data@users.noreply.github.com>

* review comments

Signed-off-by: badalprasadsingh <badal@datazip.io>

* fix: minor

Signed-off-by: badalprasadsingh <badal@datazip.io>

* fix: lint

Signed-off-by: badalprasadsingh <badal@datazip.io>

* fix: lint

Signed-off-by: badalprasadsingh <badal@datazip.io>

* fix: minor lint issues

* import feature

Signed-off-by: badalprasadsingh <badal@datazip.io>

* minor

Signed-off-by: badalprasadsingh <badal@datazip.io>

* Merge pull request #346 from datazip-inc/fix/trivy_docker

fix: suppress CVE-2026-34040 in Trivy until testcontainers-go upgrade

* review comments

Signed-off-by: badalprasadsingh <badal@datazip.io>

* fix: minor

Signed-off-by: badalprasadsingh <badal@datazip.io>

* fix: lint

Signed-off-by: badalprasadsingh <badal@datazip.io>

* fix: lint

Signed-off-by: badalprasadsingh <badal@datazip.io>

---------

Signed-off-by: badalprasadsingh <badal@datazip.io>
Co-authored-by: vishal-datazip <vishal@datazip.io>
Co-authored-by: Ankit Sharma <111491139+hash-data@users.noreply.github.com>

* fix: minor

Signed-off-by: badalprasadsingh <badal@datazip.io>

* fix: minor

Signed-off-by: badalprasadsingh <badal@datazip.io>

* fix: minor lint issues

Signed-off-by: badalprasadsingh <badal@datazip.io>

* fix: minor

Signed-off-by: badalprasadsingh <badal@datazip.io>

* minor

Signed-off-by: badalprasadsingh <badal@datazip.io>

* review changes + lock

Signed-off-by: badalprasadsingh <badal@datazip.io>

* fix: lint

Signed-off-by: badalprasadsingh <badal@datazip.io>

* fix: minor

Signed-off-by: badalprasadsingh <badal@datazip.io>

---------

Signed-off-by: badalprasadsingh <badal@datazip.io>
Co-authored-by: vishalm0509 <vishal@datazip.io>
Co-authored-by: Ankit Sharma <111491139+hash-data@users.noreply.github.com>
Base automatically changed from feat/fusion to refactor/etl-handlers April 6, 2026 15:14
Base automatically changed from refactor/etl-handlers to staging April 7, 2026 09:42
Comment thread server/routes/router.go
Comment on lines -101 to -108
// Project settings routes
web.Router("/api/v1/project/:projectid/settings", h, "put:UpsertProjectSettings")
web.Router("/api/v1/project/:projectid/settings", h, "get:GetProjectSettings")

// validation routes
web.Router("/api/v1/project/:projectid/check-unique", h, "post:CheckUniqueName")

// platform routes
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add these comments back

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread server/internal/appconfig/appconfig.go Outdated
Comment on lines +13 to +15
CopyRequestBody bool
MaxMemory int64
MaxUploadSize int64
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we remove CopyRequestBody

Comment thread server/internal/handlers/utils.go Outdated
return projectID, nil
}

func getIDParam(c *gin.Context, key string) (int, error) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

key always will be "id" here, can we avoid passing in function

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but for other modules will it still be id always ? since we are using this as a global util for all the modules

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made changes anyway since the name is explicitly GetIDParam but the above is something we should think about

Comment thread server/internal/database/job.go Outdated
}

// GetAll retrieves all jobs
func (db *Database) ListJobs() ([]*models.Job, error) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dead code

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, removed.

var users []*models.User
_, err := db.ormer.QueryTable(constants.TableNameMap[constants.UserTable]).All(&users)
err := db.conn.Find(&users).Error
return users, err
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fmt.Errorf("failed to find user: %s", err)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here, err can be nil as well. This is the design we are following in the database layer.

We are adding a proper error message in the service layer to which this is appended

Comment thread server/internal/handlers/etl/job.go Outdated
Comment on lines +585 to +586
c.Status(http.StatusOK)
if err := h.etl.StreamLogArchive(id, filePath, c.Writer); err != nil {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if StreamLogArchive returns an error without writing any bytes, it would return 200 OK with an empty response

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, made changes

Comment thread server/internal/handlers/etl/source.go
Comment thread server/internal/httpserver/server.go Outdated
}
}

func (s *Server) Engine() *gin.Engine {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where are we using this?

Copy link
Copy Markdown
Collaborator Author

@vishalm0509 vishalm0509 Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed, was using it earlier

Comment thread server/internal/services/etl/user.go Outdated
// User-related methods on AppService

func (s Service) CreateUser(_ context.Context, req *models.User) error {
func (s *Service) CreateUser(_ context.Context, req *models.User) error {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why pointer receiver?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made changes

Comment thread server/routes/router.go Outdated
// platform routes
web.Router("/api/v1/platform/releases", etlHandler, "get:GetReleaseUpdates")
web.Router("/api/v1/platform/opt/status", h, "get:GetoptimizationStatus")
etl := engine.Group("/api/v1")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in beego we were applying auth for /api/* path

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

	// Apply auth middleware to protected routes
	web.InsertFilter("/api/*", web.BeforeRouter, middleware.AuthMiddleware)

Auth middlware only applied to routes with prefix /api

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes
now it is applying to -> etl := engine.Group("/api/v1"),etl.Use(h.AuthMiddleware())

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, made changes

Comment thread server/internal/database/source.go Outdated
source.Config = eConfig
_, err = db.ormer.Update(source)
return err
return db.conn.Updates(source).Error
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gorm.Updates() Silently Skips Zero-Values on Structs
please check following doc
https://gorm.io/docs/update.html#Updates-multiple-columns

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2026-04-14 at 15 24 14

None of these can be zero value, because in the BindAndValidate we are mentioning the fields as required

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still we should use correct function

v := viper.New()

// Note: config priority: env variables -> file (app.yaml)
v.SetConfigFile("./conf/app.yaml")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can it cause any issue in k8s where all configs come from env vars

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If env is set then we prioritize env over file

Comment thread server/internal/handlers/session.go Outdated
return fmt.Errorf("failed to marshal session payload: %w", err)
}

err = s.db.UpsertSession(sessionID, payload, expiresAt)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why upsert not create

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create makes sense here. Made changes

Comment thread server/routes/router.go Outdated
// platform routes
web.Router("/api/v1/platform/releases", etlHandler, "get:GetReleaseUpdates")
web.Router("/api/v1/platform/opt/status", h, "get:GetoptimizationStatus")
etl := engine.Group("/api/v1")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes
now it is applying to -> etl := engine.Group("/api/v1"),etl.Use(h.AuthMiddleware())

func configureMode(cfg *appconfig.Config) {
switch cfg.RunMode {
case "localdev":
gin.SetMode(gin.DebugMode)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gin.SetMode() is a global setter that must be called before any gin.New() or gin.Default() call. Calling it after the engine is already created and middleware is already registered changes the global mode but has no effect on the already-constructed engine.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will not affect the code. But it's mentioned as good practice. Moved it to the top

configureMode(cfg)
configureBaseRoutes(engine)

if cfg.RunMode == "localdev" {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are checking runmode redundantly can we avoid this and check run mode at one place for all ops

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are just reading the value from the already loaded config. All these are separate operations and cannot be grouped together.

Comment thread server/routes/router.go Outdated
if h.Optimization != nil {
optHandler := h.Optimization
opt := engine.Group("/api/opt/v1")
opt.Use(h.AuthMiddleware())
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

h.AuthMiddleware() is called twice

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was called twice because we had 2 separate route groups for ETL and OPT. Now we are using a root API group where I have applied the middleware. Solved

Comment thread server/routes/router.go

// piggy backing
web.Router("/api/opt/v1/*", optHandler, "get:PiggyBacking;post:PiggyBacking;put:PiggyBacking;delete:PiggyBacking")
type ModuleNoRouteHandler struct {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move the struct and function in httpserver folder

Copy link
Copy Markdown
Collaborator Author

@vishalm0509 vishalm0509 Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we can move it. DOne

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The noModuleConfiguration is better if it's in router.go as it's related to that. Move the actual implementation to httpserver package.

Comment thread server/internal/httpserver/server.go Outdated
// Register optimization as a module fallback for unmatched /api/opt/v1/*.
// This avoids route tree conflicts from wildcard catch-all registration.
moduleHandlers = append(moduleHandlers, routes.ModuleNoRouteHandler{
PathPrefix: "/api/opt/v1/",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should place all the routes together in router.go

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, moved


const frontendDistPath = "/opt/frontend/dist"

type Server struct {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be better if we create all the functions with server as receiver

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants