-
Notifications
You must be signed in to change notification settings - Fork 357
add eskip json unmarshalling #471
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
base: master
Are you sure you want to change the base?
Conversation
Looks good (for my limited understanding of Go). As for the tests, it might not be very idiomatic, but it might be nice to have some kind generative tests, that ensure:
|
ok, thanks, will add such tests |
@aryszka is this still something we want to have, if so I can pick it up probably, otherwise lets close the PR. |
@grassator yes, we need this 😄 |
@aryszka I'm picking this up then. |
6d66bca
to
01d8b85
Compare
@aryszka I've rebased on top of master and had to make a few changes on the go. Most of them are still keeping API compatible, the only really breaking change if someone was creating |
eskip/json.go
Outdated
func (p *Predicate) MarshalJSON() ([]byte, error) { | ||
return marshalNameArgs(p.Name, p.Args) | ||
} | ||
|
||
// UnmarshalJSON returns the JSON representation of a predicate. |
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.
Are you sure that you don’t do it the other way around?
Marshal and unmarshal have very similar doc strings.
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 agree that the doc comment should rather say something like this:
"UnmarshalJSON parses a predicate object from its JSON representation."
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.
Updated to your version
eskip/json.go
Outdated
}{ | ||
var buf bytes.Buffer | ||
e := json.NewEncoder(&buf) | ||
e.SetEscapeHTML(false) // why not working :( |
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.
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 was your comment :) I will check
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.
So this took a bit to figure out. The problem is that the setting only has effect if you are using an encoder directly. If you use json.Marshal
there is no way to unset it.
https://golang.org/src/encoding/json/encode.go?s=6521:6546#L160
eskipfile/watch.go
Outdated
return WatchFile(fileName, eskip.ParseBytes) | ||
} | ||
|
||
func WatchFile(fileName string, parseFunc eskip.ParseFunc) *WatchClient { |
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.
the name of this function should reflect what's the difference from the simple Watch(). My candidate is: WatchParser()
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.
Made it WatchWithParser
Should better reflect the difference from original `Watch` function
@@ -334,6 +336,11 @@ func Parse(code string) ([]*Route, error) { | |||
return routeDefinitions, nil | |||
} | |||
|
|||
// Parses a route expression or a routing document to a set of route definitions. |
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.
According the https://golang.org/doc/effective_go.html#commentary comments should start with function name:
// Parses a route expression or a routing document to a set of route definitions. | |
// ParseBytes parses a route expression or a routing document to a set of route definitions. |
It some languages, to generate docs, function name is ignored, that's why doc comments starts with function name.
Fixes #879