Skip to content

Commit

Permalink
📚 docs: update README.md #2
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen215 committed Dec 14, 2024
1 parent 1ba735d commit 9a4ba81
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 9a4ba81

Please sign in to comment.