From 9a4ba8178e48d62d56ceeb30ae09288ad12c1c5e Mon Sep 17 00:00:00 2001 From: arisnguyenit97 Date: Sat, 14 Dec 2024 22:40:07 +0700 Subject: [PATCH] :books: docs: update README.md #2 --- README.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/README.md b/README.md index 752bd0c..82afcbb 100644 --- a/README.md +++ b/README.md @@ -270,6 +270,53 @@ func main() { } ``` +> Example of creating a wrapper-based standardized API response + +```go +package main + +import ( + "fmt" + + "github.com/sivaosorg/unify4g" + "github.com/sivaosorg/wrapify" +) + +func main() { + p := wrapify.NewPagination(). + WithIsLast(true). + WithPage(1). + WithTotalItems(120). + WithPage(1000). + WithTotalPages(34). + WithPerPage(2) + w := wrapify.New(). + WithStatusCode(200). + WithTotal(1). + WithMessagef("How are you? %v", "I'm good"). + WithDebuggingKV("refer", 1234). + WithDebuggingKVf("___abc", "trace sessions_id: %v", unify4g.GenerateCryptoID()). + WithBody("response body here"). + WithPath("/api/v1/users"). + WithCustomFieldKVf("fields", "userID: %v", 103). + WithPagination(p) + if !w.Available() { + return + } + fmt.Println(w.Json()) + fmt.Println(w.StatusCode()) + fmt.Println(w.StatusText()) + fmt.Println(w.Message()) + fmt.Println(w.Body()) + fmt.Println(w.IsSuccess()) + fmt.Println(w.Respond()) + fmt.Println(w.Meta().IsCustomFieldPresent()) + fmt.Println(w.Meta().IsApiVersionPresent()) + fmt.Println(w.Meta().IsRequestIDPresent()) + fmt.Println(w.Meta().IsRequestedTimePresent()) +} +``` + ### Contributing To contribute to project, follow these steps: