-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
devices handler #23
Conversation
658b596
to
9c360c9
Compare
There was a problem hiding this 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() { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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;`) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
No description provided.