Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: refactor server code #9

Closed
wants to merge 3 commits into from
Closed

Conversation

swarit-pandey
Copy link

@swarit-pandey swarit-pandey commented Sep 29, 2024

Purpose: The current code can be potentially improved to use standard REST based structure used in Go projects. Currently there is no scope of dependency injection, seperation of concerned layers which could potentially create issues going ahead (as we add more routes and businees logic).

This PR overhauls a lot of code that was implemented previously (excpet core logic). The new changes introduces:

  • Seperation of concerns with proper constructors
  • Not letting server crash when errors are encountered instead return them to clients
  • Interface based layer initialization for better integration testing (as mocking interfaces is super easy, while structs are concrete)

Potential improvements:

  • Routes can be moved to a seperate package
  • A more dedicated library can be used such as Gin
  • Errors should be properly wrapped before reaching clients

Caveats:
This is not to undermine the work previous contributors did, if the reviewers/maintainers think that this change is 'very drastic', feel free to close the PR. But since a lot of service layer code is still to be implemented we can potentially improve the code.

Thanks.

@lucifercr07
Copy link
Contributor

lucifercr07 commented Oct 1, 2024

@swarit-pandey thanks for this contribution, please resolve the conflicts once.

@swarit-pandey
Copy link
Author

@swarit-pandey thanks for this contribution, please resolve the conflicts once.

@lucifercr07 Sure, will get it done by EOD today.

config/config.go Outdated
@@ -14,7 +14,7 @@ type Config struct {
}

// LoadConfig loads the application configuration from environment variables or defaults
Copy link

@santhosh-chinnasamy santhosh-chinnasamy Oct 1, 2024

Choose a reason for hiding this comment

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

fn name is self explanatory we can remove or update the comment as required

Suggested change
// LoadConfig loads the application configuration from environment variables or defaults
// loads the application configuration from environment variables or defaults

Copy link
Author

@swarit-pandey swarit-pandey Oct 1, 2024

Choose a reason for hiding this comment

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

In Go, if a function is public then it should have a comment starting with its name.

Signed-off-by: Swarit Pandey <[email protected]>
// ExecuteCommand executes a command based on the input
func (db *DiceDB) ExecuteCommand(command *cmds.CommandRequest) (interface{}, error) {
switch command.Cmd {
case "GET":
Copy link
Contributor

Choose a reason for hiding this comment

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

Please match the behaviour of current changes similar to this.

@@ -4,3 +4,9 @@ type CommandRequest struct {
Cmd string `json:"cmd"`
Args []string
}

type CommandRequestArgs struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not required

@@ -0,0 +1,3 @@
package service

// TODO: Implement me
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are these empty?

@@ -0,0 +1,14 @@
package repository

type GetRequest struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to keep this generic, not feasible to be done for multiple commands getting generated.

@lucifercr07
Copy link
Contributor

Closing the PR, since inactive from sometime.

@lucifercr07 lucifercr07 closed this Oct 6, 2024
@swarit-pandey
Copy link
Author

Hey folks, sorry for not being able to continue working on this. I got occupied with other work related stuff, thanks for taking time to review.

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