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
Add GatewayPort configuration #67
Conversation
Signed-off-by: Jonatas Baldin <jonatas.baldin@gmail.com>
Signed-off-by: Jonatas Baldin <jonatas.baldin@gmail.com>
Signed-off-by: Jonatas Baldin <jonatas.baldin@gmail.com>
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 looks good to me.
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.
Sorry, just noticed these comments were pending and not sent yet.
readconfig.go
Outdated
@@ -114,6 +120,7 @@ func (ReadConfig) Read() QueueWorkerConfig { | |||
type QueueWorkerConfig struct { | |||
NatsAddress string | |||
GatewayAddress string | |||
GatewayPort string |
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 read as an int
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.
Good catch
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.
Fixed.
cfg.GatewayPort = val | ||
} else { | ||
cfg.GatewayPort = "8080" | ||
} |
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.
We could probably concatenate the value once here instead of passing two arguments everywhere.
I think the new env var makes sense to prevent issues upgrading versions.
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.
Fixed.
main.go
Outdated
pathVal, | ||
qs) | ||
|
||
if config.GatewayInvoke { | ||
functionURL = fmt.Sprintf("http://%s:8080/function/%s%s%s", | ||
functionURL = fmt.Sprintf("http://%s:%s/function/%s%s%s", |
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.
We should probably make the entire url configurable and do something like url.Parse()
. Opens the door for https etc.
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 nice!
We could add yet a new variable called cfg.GatewayProtocol
with http
as the default value for backwards compatibility. What do you think?
Also, should we open a new issue/PR for that?
Signed-off-by: Jonatas Baldin <jonatas.baldin@gmail.com>
Signed-off-by: Jonatas Baldin <jonatas.baldin@gmail.com>
I closed the PR by mistake 🤦♂ @alexellis, could you re run the build, please? Also, you'll note that since I'm concatenating the |
hey @alexellis, any comments on this? ✨ could u run the build again? hehe 🏃 |
@alexellis please advise |
Retrying the build. |
main.go
Outdated
@@ -30,14 +30,15 @@ func makeFunctionURL(req *queue.Request, config *QueueWorkerConfig, path, queryS | |||
if len(path) > 0 { | |||
pathVal = path | |||
} | |||
functionURL := fmt.Sprintf("http://%s%s:8080%s%s", | |||
functionURL := fmt.Sprintf("http://%s%s:%d%s%s", |
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 has been changed incorrectly.
This line does not invoke via the gateway.
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.
@acornies FYI ^
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.
Changed.
readconfig_test.go
Outdated
@@ -76,12 +77,18 @@ func Test_ReadConfig(t *testing.T) { | |||
t.Fail() | |||
} | |||
|
|||
expected = "test_gatewayaddr" | |||
expected = "test_gatewayaddr:8080" |
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 you use the word want
instead of expected
and gotinstead of
actual`? Thank you, see: https://blog.alexellis.io/golang-writing-unit-tests/
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 we should then refactor the whole test file, since all tests are using expected
and actual
and we should do this in another PR. Do you agree?
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.
Yes, but this is not refactoring, it's naming. Please go ahead.
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.
Found a potential bug in the implementation, please see comment.
Signed-off-by: Jonatas Baldin <jonatas.baldin@gmail.com>
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.
Comments answered 🎉
main.go
Outdated
@@ -30,14 +30,15 @@ func makeFunctionURL(req *queue.Request, config *QueueWorkerConfig, path, queryS | |||
if len(path) > 0 { | |||
pathVal = path | |||
} | |||
functionURL := fmt.Sprintf("http://%s%s:8080%s%s", | |||
functionURL := fmt.Sprintf("http://%s%s:%d%s%s", |
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.
Changed.
readconfig_test.go
Outdated
@@ -76,12 +77,18 @@ func Test_ReadConfig(t *testing.T) { | |||
t.Fail() | |||
} | |||
|
|||
expected = "test_gatewayaddr" | |||
expected = "test_gatewayaddr:8080" |
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 we should then refactor the whole test file, since all tests are using expected
and actual
and we should do this in another PR. Do you agree?
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.
Sending comments from mobile
readconfig_test.go
Outdated
if config.GatewayAddress != expected { | ||
t.Logf("Expected GatewayAddress `%s` actual `%s`\n", expected, config.GatewayAddress) | ||
t.Fail() | ||
} | ||
|
||
expectedGatewayPort := 8080 | ||
if config.GatewayPort != expectedGatewayPort { | ||
t.Logf("Expected GatewayPort `%d` actual `%d`\n", expectedGatewayPort, config.GatewayPort) |
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.e. GatewayPort want %d, got %d
Signed-off-by: Jonatas Baldin <jonatas.baldin@gmail.com>
Signed-off-by: Jonatas Baldin <jonatas.baldin@gmail.com>
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.
LGTM
Description
Allows the User to configure a custom GatewayPort in nats-queue-worker. Fixes #59.
Motivation and Context
Types of changes
Checklist:
git commit -s