Commit Graph

126 Commits (ec48a76f14914bbac38a992a25f2cbc91643999a)

Author SHA1 Message Date
ACHMAD IRIANTO EKA PUTRA 9a56a1bf6d
v3: Add QueryParser for get query using generic (#2776)
* Add QueryParser method and tests

Introduced a new method, QueryParser, to parse query parameters from a given context into specified types: integer, boolean, float, and string. The method provides default values for empty or invalid keys. Corresponding tests for each type have also been added to validate the functionality.

* Refactor QueryParser and add string support

Refactored the existing QueryParser method in the code to simplify its structure. Instead of reflecting on types, it now uses explicit type checking. In addition to the existing support for integers, booleans, and floats, the QueryParser method now also supports string parsing. Corresponding tests for the updated method and new feature were added as well.

* Update example call in method comment

Updated the method call example in the comment for the Query function in the ctx.go file. Previously, it was incorrectly demonstrating a call to "QueryParser("wanna_cake", 1)", but this has been updated to correctly represent the method it is commenting, resulting in "Query("wanna_cake", 1)".

* Refactor Query function in ctx.go

The update introduces better type assertion handling in the Query function. A switch statement is now employed to determine the type of the value as opposed to the previous if clauses. In addition, a validation step has been added to ensure the context passed into the function is of the correct type.

* Refactor type handling in Query function

The Query function in ctx.go has been refactored for better and clearer type handling. The code now uses a 'QueryType' interface, replacing explicit string, bool, float, and int declarations. This change also improves the error message when a type assertion fails, making it more descriptive about the specific failure.

* Add type assertion check in ctx.go

Updated the code in ctx.go to add a type assertion check for all case statements. The function now checks if the returned value is of the expected type, and if not, it throws a panic with a description of the failed type assertion.

* Refactor Query function to support more data types

The Query function has been expanded to support a broader range of data types. This includes support for extracting query parameters as different types of integers (both signed and unsigned), strings, floats, and booleans from the request's URI. The function now includes comprehensive parsing capabilities that allow for improved handling of different data types.

* Refactor Query function documentation

The documentation for the Query function has been updated to emphasize its versatility in handling various data types. The changes also clarify how the function operates and demonstrates the usage and benefits of providing a defaultValue. The different variations of QueryBool, QueryFloat, and QueryInt were removed, as they are now encompassed by the enhanced Query function.

* Add benchmark tests for Query function

Benchmark tests have been added to evaluate the performance of the Query function for different data types. These tests will help in assessing the efficiency of the function when processing various queries. The addition of these benchmarks will aid in future optimizations and enhancements of the function.

* Update generic Query function signature

The signature of the generic Query function has been updated to accept different types of data as arguments. The change improves flexibility of the function by allowing it to handle different data types, effectively making it a versatile tool in processing various queries.

* Modify `ctx.Query()` calls in documentation

`ctx.Query()` calls in the ctx.md documentation file were updated to remove the `ctx.` prefix. This is consistent with the typical use cases and makes the code examples more clear and easy to understand.

* Refactored assertValueType function and improved query parameter documentation

Updated the assertValueType function to utilize the utils.UnsafeBytes method for byte conversion. Enhanced the documentation for query parameter types to offer clearer, more comprehensive explanations and examples, including QueryTypeInteger, QueryTypeFloat, and subcategories.

* Update Query method calls to use new fiber.Query syntax

In this commit, the conventional `c.Query()` calls across multiple middleware and document files are updated to use the new `fiber.Query` syntax. The changes align with the updated function signatures in Fiber library that provides type-specific querying. These enhancements contribute to the project's overall robustness and consistency.

* Add Query method to get query string parameters

* Replace 'utils.UnsafeBytes' with 'ctx.app.getBytes'

In the query method, the utils.UnsafeBytes function was replaced with the ctx.app.getBytes method. This change enhances the extraction of query string parameters by making it safer and more context-specific.

* Refactor parsing functions in query handlers

The parsing functions in query handlers have been refactored to simplify the process. Parsing code has been extracted into dedicated functions like 'parseIntWithDefault' and 'parseFloatWithDefault', and they now reside in a new utils file. This modularization improves readability and maintainability of the code. Additionally, documentation is updated to reflect the changes.

* Refactor parsing functions in ctx.go

The parsing functions have been restructured to enhance readability and reduce repetition in the ctx.go file. This was achieved by creating generalised parsing functions that handle defaults and ensure the correct value type is returned. As a result, various single-use parsing functions in the utils.go file have been removed.

* Refactor code to centralize parsing functions
2024-01-19 14:43:44 +01:00
Fenny 77843393c4 🏃‍♀️ move utils to internal
Co-Authored-By: RW <7063188+ReneWerner87@users.noreply.github.com>
2020-09-14 09:27:25 +02:00
Fenny a09daabfee move utils to internal 2020-09-14 09:24:48 +02:00
Fenny a3cac71ae8 🔦 move utils to internal 2020-09-14 09:09:06 +02:00
Fenny ec5d66e7a8 v2 2020-09-13 11:20:11 +02:00
ReneWerner87 df3c48a734 🌵hybrid routing with tree and fast router 2020-08-10 10:51:38 +02:00
ReneWerner87 945b61d1c3 🌵hybrid routing with tree and fast router 2020-08-09 21:53:15 +02:00
kiyon 9cac73e7ba 👷 fix Security / Gosec, handle f.Close error 2020-07-29 11:29:27 +08:00
kiyon 7863cd1458 👷 add ctx.Render test cases 2020-07-29 11:07:47 +08:00
kiyon 3779723507 👷 add app.Test test cases 2020-07-29 09:14:15 +08:00
kiyon 1ee7f62c35 ✈️ improve isNoCache a little bit 2020-07-28 12:03:52 +08:00
Fenny 87127f571a 🧹 Remove deprecated Templates 2020-07-28 04:36:56 +02:00
fenny d06256c944
Merge pull request #675 from larrylv/larrylv/improve_no_cache_header_matching
🚀 Don't use regexp for no-cache value check
2020-07-27 04:43:19 +02:00
Larry Lv 931df73503
lint 2020-07-26 19:03:45 -07:00
Larry Lv b310f0f501
🧹 Don't allocate string slice in isEtagStale 2020-07-26 18:55:57 -07:00
Larry Lv fc85699a95
🧹 Refactor etag stale checking 2020-07-26 18:53:26 -07:00
Larry Lv fd75ef0fbe
🚀 Don't use regexp for no-cache value check 2020-07-25 22:35:43 -07:00
ReneWerner87 b34a77bc96 💉 Sync route method metadata
Co-authored-by: Fenny <fenny@gofiber.io>
2020-07-21 23:30:52 +02:00
fenny 8605857678
🚀 refactor: improve logic method BodyParser
🚀 refactor: improve logic method BodyParser
2020-07-14 22:55:20 -04:00
renanbastos93 d61e478578 🚀 refactor: improve logic method BodyParser 2020-07-14 12:18:44 -03:00
Fenny 0a3eb08530 Merge remote-tracking branch 'upstream/master' 2020-07-14 14:35:26 +02:00
ReneWerner87 fa9128b7d6 🐞 prevent duplicates in ctx.Append for similar wording of the value 2020-07-14 12:21:55 +02:00
renanbastos93 e070968d2d 🚀 refactor: change status code number to constant 2020-07-14 00:55:41 -03:00
Fenny 20cba2604b 🔌 Add IPv6 support
Co-Authored-By: kiyon <kiyonlin@163.com>
2020-07-14 03:53:58 +02:00
Fenny b8fbaca1ea 🔌 Add IPv6 Support
Co-Authored-By: kiyon <kiyonlin@163.com>
2020-07-14 03:02:26 +02:00
kiyon b7b14bcbc3 🍞 adjust import 3rd package location 2020-07-13 14:01:11 +08:00
kiyon 9d9cfa8424 🚨 extract func quoteString() for ctx.Attachment and ctx.Download 2020-07-13 12:37:50 +08:00
kiyon 2cfc1b1546 👷 Extract "USE" to a global const variable 2020-07-12 23:54:22 +08:00
Fenny 94fa10c85b 🐛 Fix typo 2020-07-10 14:15:41 +02:00
Fenny 3484897184 🐛 Avoid method override on 405 2020-07-10 13:57:53 +02:00
kiyon ce3d44613c 🔧 fix #556 remove ctx.matched things 2020-07-07 23:25:02 +08:00
Fenny a21897d0de 🔨 Define return Addr in Test 2020-07-05 11:09:01 +02:00
Fenny 5250a33879 Add defaultvalue 2020-07-04 10:11:23 +02:00
ReneWerner87 d57651835b improve routing performance 2020-06-29 22:51:41 +02:00
Fenny 578e566475 Add 405 Support 2020-06-21 12:17:22 +02:00
Fenny 4102262dd7 Add benchmark 2020-06-21 11:11:45 +02:00
Fenny 8db7e169a3 Update utils.go 2020-06-21 11:04:46 +02:00
Fenny ef264df776 Update utils.go 2020-06-21 11:03:17 +02:00
Fenny 3568613dfa Update 405 Tests 2020-06-21 11:02:17 +02:00
Fenny 09116ae22b Add 405 Support 2020-06-21 10:47:03 +02:00
Fenny 44d739496d Add 405 Method Not Allowed 2020-06-20 17:26:48 +02:00
wernerr e674d679df move path matching and registration in separate file "path.go" 2020-06-14 12:37:09 +02:00
wernerr f816c6706f add support for -. chars in the route 2020-06-14 12:06:14 +02:00
wernerr bbcff3f375 add support for -. chars in the route 2020-06-13 18:34:31 +02:00
wernerr 0a615653cb add support for -. chars in the route 2020-06-13 18:18:25 +02:00
wernerr 91a5185307 add support for -. chars in the route 2020-06-13 16:54:38 +02:00
wernerr 3e6261b7c4 add support for -_. chars in the route 2020-06-12 16:06:12 +02:00
wernerr f4292c9030 add support for -_. chars in the route 2020-06-12 13:29:16 +02:00
Fenny 5d649f7270 🚚 Add Errors 2020-06-06 18:53:51 +02:00
Fenny cd9aa0f9c5 ⌨️ Fix typo 2020-06-06 07:30:30 +02:00