-
Notifications
You must be signed in to change notification settings - Fork 413
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
Query json response using gjson #43
Conversation
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 is a really good start - the gjson search works quite well, and the display of what wuzz thinks the content type is is clever. There's some things that I think need to be addressed before this can be merged, in addition to my notes on individual segments of the code:
-
You should be able to use textual search on any textual content, including JSON. IMO both
gjson
andxpath
search should be optional. This touches on something I've been mulling on for a while, which is different kinds of search - personally, I'd like to add a regex search that shows the matching lines, instead of just the matching text. There needs to be some code organization and UI work to support this. IMO, we should wait for this to be decided on and implemented before adding any alternate forms of search, as I see this being very confusing for people who don't follow the development here on GitHub. -
We need to figure out what the
Request
type should look like in the long-term. This is something I'm dealing with in one of my own branches (https://github.com/benaiah/wuzz/tree/json-highlighting), where I have similarly separated different kinds of request body.I think the long-term solution to this should be to take this stuff out of
Request
, and leave that object unmodified by display code. I think we should have a separate struct to store modified versions of the request data - perhapsRequestDisplay
. This is partially my fault - I started the trend of directly modifyingRequest
with my JSON formatting patch early on, which mutatedr.RawResponseBytes
to format. I think that was a poor choice for long-term program structure.
In addition, I think @asciimoo should weigh in on the code organization. We'll definitely need to reorganize as the program grows, but it should probably be something thought-out and discussed for a while before we begin pulling stuff out of wuzz.go in an ad-hoc fashion. It impacts a lot more than just this search stuff - it requires that many or all of the existing PRs be modified to fit the new structure, it affects how the different parts of the application interoperate, and it has major effects on the git history.
Thanks so much for the PR! It's great work, and it's definitely a step towards a more flexible wuzz.
search.go
Outdated
return SearchText(request, searchString) | ||
} | ||
|
||
if request.ContentType == "application/json" { |
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.
Matching the whole ContentType string does not work here - for instance, a Content-Type: application/json; charset=utf-8
results in [unknown content]
, and neither gjson nor textual search works in this case.
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.
https://golang.org/pkg/mime/#ParseMediaType looks like the correct solution for determining the MIME value of a Content-Type header. We'll probably want to parse the header up-front and store it somewhere - perhaps Request.ContentType
should be changed to use the following type:
type ContentType struct {
MediaType string
Params map[string]string
}
This could then be populated by mime.ParseMediaType
.
@asciimoo: thoughts?
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 think there are many more things to do for this too. However, I personally like to have those fixes in a separate commit(s) instead, which is why I didn't want to include the mimetype detection in this commit.
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.
That's fair, but in the meantime this should at least be changed to a strings.Contains(request.ContentType, "application/json")
so it actually works consistently. The current behavior is really confusing if you're not developing wuzz.
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.
Roger, will fix this and the one above with the "Index == -1"
search.go
Outdated
// returns title, display, error | ||
func Search(request *Request, searchString string) (string, []byte, error) { | ||
isBinary := (strings.Index(request.ContentType, "text") == -1 && | ||
strings.Index(request.ContentType, "application") == -1) |
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.
Why do you use strings.Index(...) == -1
instead of !strings.Contains(...)
? The latter would be clearer, IMO.
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.
Oops, this is my bad. When I pull out the code, I didn't change the logic from the previous part.
Agreed. I would like to add a key to toggle the type of search that you want to perform, with "auto" as the default.
I see. We should really decide this soon :P, seeing how many people are interested in helping.
For this, I have moved them to a ParsedResponseBody which is a Personally I would store this as part of the display view.
Roger. So I guess I'll wait before continuing =) |
@ZwodahS sounds good. @asciimoo has been active every day since the project started so far, so I'm not concerned that this will stall too long. He specifically requested that I don't merge PRs without him getting a chance to check them out, so it'd be waiting on him anyway.
Agreed. When I have my highlighting branch ready I'll need to add another copy of the response body with highlighting, as you can't usefully search text that's full of terminal escape codes. I wouldn't want to put that in Thanks again for the contribution, it's really very useful. |
This is exactly how I imagined this functionality =)
I don't like to over-engineer the problem. File based separation by logical blocks is enough at first imho. And we can create modules if we will have tests and more complex features. What do you think?
As I saw, |
Makes sense to me. I definitely don't think we're at the point we need submodules - the wuzz namespace isn't very crowded at the moment.
Oh, awesome. Might not need to store an extra copy anyway. I think the buffer/buffer display separation can probably wait for another PR with its own discussion, so I think that the code style/functionality problems I addressed are resolved (thanks for the quick work @ZwodahS!). All this is waiting on now is the search type toggling, as far as I can tell. |
@ZwodahS you may already be aware of this, but when you rebase the PR onto the current master, you'll probably want to squash the |
What kind of git workflow do you guys prefer ?
|
@ZwodahS hmm, I've never actually discussed this with @asciimoo. This is the first PR where this has come up. I assumed we were planning on using a rebase/squash based workflow, as that's the norm, but if he prefers merges that's fine with me (it's his project after all). I think the [fix] commits should probably be removed from the history either way, but as for the overall merging strategy I'd have to defer. As for question 1, I don't think it really matters whether you squash as you go or squash before the PR is good to go - it wouldn't affect the history of the main repo (that's the point of squashing). |
rebased and squashed. I think this is what you want, if not let me know. I kept them in 2 commits, because one refactored the code into a new file and the other added the query. |
Yeah, the two commits should be fine IMO. |
Usually, I don't have strict git workflow rules in my projects. Do we want here? |
@asciimoo I'm in favor of rebasing, at least as the normal way to do it. It's the most common practice with Github-based open source projects, in my experience. My guess is that most people on Github are more used to using rebase to merge PRs. There might be situations where merge commits are more appropriate for history purposes or significantly easier to do, but I haven't seen any in this project. Rebase merging makes the history much easier to follow, IMO, so I'd definitely be in favor of it as a default, though I'm not dogmatic about it. I don't think we should require that PRs get squashed into one commit, though I would like changes made during PR review to get squashed (like what @ZwodahS and I were discussing in this conversation), so we don't get changes in the history that were never actually part of the main repo. For instance, I think this PR is appropriate as two commits due to the separation of the search code into its own file, which is a pretty significant change that should be in the commit log, but I wouldn't want the commits that I addressed my review to be in the project history. |
Totally agreed with @Benaiah here on squashing into 1 commit if they aren't part of the original code and splitting them into different commits if they are of different nature. The other question is whether if contributors should rebase to the new master or the one merging it. |
Hi, this is getting hard to rebase as more things are added to the search screen. In that case, I would suggest just closing this and refactor it later once things settle down and reimplement this later. Not really hard since we are just wrapped gjson here. |
@ZwodahS sorry for the delayed response. I still think this is a great feature, but wuzz stabilized/changed a lot in the previous weeks. Could you please adapt the PR to the latest codebase? |
I don't think I will be able to find time to do this any time soon. I think someone should just take it and adapt it instead. Sorry about that. |
@ZwodahS no problem, I'll do it. This PR is a good base, thank you for it. |
added in 82d1ae6 |
the query syntax is using https://github.com/tidwall/gjson
If there is a need, we can create a new query syntax but that is not necessary at this moment.
I also took out the search code into
search.go
, I hope that is okay. This way, we can put all the searching code in one place.Issue #40