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

devices handler #23

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

devices handler #23

wants to merge 2 commits into from

Conversation

discentem
Copy link
Owner

No description provided.

@radsec radsec force-pushed the fix_readme_and_enrollment_endpoint branch from 658b596 to 9c360c9 Compare May 31, 2022 18:30
Base automatically changed from fix_readme_and_enrollment_endpoint to main May 31, 2022 18:31
Copy link
Collaborator

@radsec radsec left a comment

Choose a reason for hiding this comment

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

since I can't mark the exact file for review...the cmd/devices/main binary should not really be published.

few changes/comments

dsn string
)

func main() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This main() should remain here in main.go under devices

Copy link
Owner Author

Choose a reason for hiding this comment

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

it is under /devices? I'm not sure what you mean.

if err != nil {
log.Fatal(err)
}
rows, err := db.Query(`select * from enrollments;`)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this be migrated to the internal folder if this logic is to only remain here....keeps the main function clean as it just calls the executing functions that are required. --> internal/devices module

Copy link
Owner Author

Choose a reason for hiding this comment

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

Fair point. will work on this.

log.Fatal(err)
}
defer rows.Close()
var devices []DeviceDTO
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would also create a types for all these under that new internal/devices module to keep this cleaner

LastSeen: lsa,
DEPProfileStatus: "unknown",
}
type Serial struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same with the types suggestion, migrate all of these to a types folder or try to consolidate types if possible for readability.

Copy link
Owner Author

Choose a reason for hiding this comment

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

I kind of disagree that Serial is worthy of being stuffed in another package somewhere. It's such a small struct that is only used here, in-line. I also don't really like the types pattern as I'd prefer to organize by business logic instead of go type.

devices = append(devices, ddto)
}

devicesHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would create a separate handlers for this. Honestly, the handler that I refactored in enroll_endpoint is very simple and allows us to add a quick logger and is pretty easy to understand the routing. Since the main purpose of this is to serve as a HTTP server, it is very clear then it should operate like that vs a CLI tool that offers up an HTTP server interface

Copy link
Owner Author

Choose a reason for hiding this comment

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

Please clarify your comment "would create a separate handlers" for this. I'm not sure what you mean.

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.

2 participants