Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃殌 Human readable BodyLimit #1874

Closed
vanodevium opened this issue Apr 22, 2022 · 13 comments 路 Fixed by #1875
Closed

馃殌 Human readable BodyLimit #1874

vanodevium opened this issue Apr 22, 2022 · 13 comments 路 Fixed by #1875

Comments

@vanodevium
Copy link
Contributor

Is your feature request related to a problem?
No

Describe the solution you'd like

What about make ability to set body size limit as human readable string?
Say we have environment variable BODY_SIZE=42MB
Then we read and set it to the fiber configuration.

Lets imagine BodyLimitString property in the fiber.Config

app := fiber.New(fiber.Config{
	BodyLimitString: os.Getenv("BODY_SIZE"),
})

And this property automatic parsed into bytes size

@ReneWerner87
Copy link
Member

would treat the outside

integer numbers are perfect for config, everything else must be converted from outside

i.e. best you build a function that parses this or we could provide something in the utils, but in the config i wouldn't anchor it additionally

@vanodevium
Copy link
Contributor Author

@ReneWerner87 Fine. Maybe we can provide some function into Config, like ParseBodyLimit() as utility?

Sorry for my persistence. I'm just starting my journey into golang development.
I want to get it right :)

@vanodevium
Copy link
Contributor Author

Or you mean utils package?

@ReneWerner87
Copy link
Member

ReneWerner87 commented Apr 22, 2022

converting does not really have anything to do with the bodylimit

we could provide a function in the utils called "ConvertToBits".

func ConvertToByte(humanReadbleBytes string) int

maybe here https://github.com/gofiber/fiber/blob/master/utils/common.go

@vanodevium
Copy link
Contributor Author

Sounds good!
Can I try to make this function?

@ReneWerner87
Copy link
Member

utils.ConvertToByte("42MB") // 4194304
utils.ConvertToByte("42MegaByte") // 4194304
utils.ConvertToByte("42MByte") // 4194304

@ReneWerner87
Copy link
Member

Sounds good! Can I try to make this function?

sure, but don麓t forget
unittests, documentation, benchmark method

@vanodevium
Copy link
Contributor Author

@ReneWerner87 #1875
Please review and give me any feedback. I really try to do my best

@ReneWerner87
Copy link
Member

Looks good, will merge it soon

@vanodevium
Copy link
Contributor Author

Tnx!

Maybe I will be a good golang developer :)

@ReneWerner87 ReneWerner87 linked a pull request Apr 24, 2022 that will close this issue
@gaby
Copy link
Member

gaby commented May 5, 2022

@vanodevium How do you use this function? There's no documentation about it. I tried:

ConvertToBytes("20MB")
utils.ConvertToBytes("20MB")
fiber.ConvertToBytes("20MB")
common.ConvertToBytes("20MB")

They all return function is "undefined"

@ReneWerner87
Copy link
Member

It's not released yet

But it's coming in the next days.

@gaby
Copy link
Member

gaby commented May 5, 2022

Thank you! 馃憤馃徎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants