-
Notifications
You must be signed in to change notification settings - Fork 50
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 dynamic port conf for restapiserver #802
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.
Thank you @betelgeuse-7 👍
This PR works nicely!
I have a minor comment for validation.
Please check the review comment and update PR if necessary.
// giving a default value of "1323" | ||
port := flag.String("port", "1323", "port number for the restapiserver to listen to") | ||
flag.Parse() | ||
|
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.
How about adding validation for the given port number? [1-65535]
If you agree, you can refer to the code below.
I tested following code myself :)
// giving a default value of "1323" | |
port := flag.String("port", "1323", "port number for the restapiserver to listen to") | |
flag.Parse() | |
// giving a default value of "1323" | |
port := flag.String("port", "1323", "port number for the restapiserver to listen to") | |
flag.Parse() | |
// validate arguments from flag | |
validationFlag := true | |
// validation: port | |
// return TRUE if your number is in [1-65535] range | |
if portInt, err := strconv.Atoi(*port); err == nil { | |
if portInt < 1 || portInt > 65535 { | |
validationFlag = false | |
} | |
} else { | |
validationFlag = false | |
} | |
if !validationFlag { | |
fmt.Printf("%s is not a valid port number.\n", *port) | |
fmt.Printf("Please retry with a valid port number (ex: -port=[1-65535]).\n") | |
os.Exit(1) | |
} |
$ ./cb-tumblebug -port=23242334
23242334 is not a valid port number.
Please retry with a valid port number (ex: -port=[1-65535]).
$ ./cb-tumblebug -port=123NiceContributor
123NiceContributor is not a valid port number.
Please retry with a valid port number (ex: -port=[1-65535]).
@betelgeuse-7 I hope to know your opinion on the Makefile. cb-tumblebug uses Makefile to build and run source code. Line 11 in e7c6243
Do you think the Makefile needs to be enhanced |
@seokho-son |
I haven't ever used Makefiles before. So unfortunately, I don't really have an opinion on that. |
/lgtm |
@jihoon-seo (I hope to know your opinion regarding |
https://stackoverflow.com/questions/2214575/passing-arguments-to-make-run 을 참고하여
default:
go build -mod=mod -o cb-tumblebug
cc:
GOOS=linux GOARCH=arm go build -mod=mod -o cb-tumblebug-arm
swag swagger:
~/go/bin/swag i -o ./api/rest/docs
proto protobuf pb:
cd api/grpc/protobuf && $(MAKE) regenerate
cbadm:
cd api/grpc/cbadm && $(MAKE)
run:
- ./cb-tumblebug
+ ./cb-tumblebug $(ARGS)
clean:
rm -v cb-tumblebug cb-tumblebug-arm
→
이렇게 하면 일단 이 PR은 LGTMT 이므로 merge 하겠습니다. 😊 |
@all-contributors please add @betelgeuse-7 code |
@betelgeuse-7 already contributed before to code |
I just discovered that we can actually pass we can run the application as follows: ( |
@betelgeuse-7 Nice suggestion! 😊 [Suggestion] default:
go build -mod=mod -o cb-tumblebug
cc:
GOOS=linux GOARCH=arm go build -mod=mod -o cb-tumblebug-arm
swag swagger:
~/go/bin/swag i -o ./api/rest/docs
proto protobuf pb:
cd api/grpc/protobuf && $(MAKE) regenerate
cbadm:
cd api/grpc/cbadm && $(MAKE)
run:
./cb-tumblebug
runwithport:
./cb-tumblebug --port=$(PORT)
clean:
rm -v cb-tumblebug cb-tumblebug-arm [Usage]
|
we can now pass port number as a command-line argument when running the application.
--port 5000
,-port 5000
,--port=5000
,-port=5000
, etc. are all valid arguments.if a given port is not present, the server will start listening on
1323
by default.