From cb7c14b43290239e0a7370a69478e039c21d9643 Mon Sep 17 00:00:00 2001 From: arisnguyenit97 Date: Sat, 14 Dec 2024 17:43:39 +0700 Subject: [PATCH] :mute: silent changes: add base function #4 #2 --- init.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/init.go b/init.go index bf168c6..8b2a1fd 100644 --- a/init.go +++ b/init.go @@ -1,6 +1,7 @@ package wrapify import ( + "fmt" "time" "github.com/sivaosorg/unify4g" @@ -431,6 +432,22 @@ func (w *wrapper) WithMessage(message string) *wrapper { return w } +// WithMessagef sets a formatted message for the `wrapper` instance. +// +// This function constructs a formatted string using the provided format string and arguments, +// assigns it to the `message` field of the `wrapper`, and returns the modified instance. +// +// Parameters: +// - message: A format string for constructing the message. +// - args: A variadic list of arguments to be interpolated into the format string. +// +// Returns: +// - A pointer to the modified `wrapper` instance, enabling method chaining. +func (w *wrapper) WithMessagef(message string, args ...interface{}) *wrapper { + w.message = fmt.Sprintf(message, args...) + return w +} + // WithBody sets the body data for the `wrapper` instance. // // This function updates the `data` field of the `wrapper` with the provided value @@ -461,6 +478,22 @@ func (w *wrapper) WithPath(v string) *wrapper { return w } +// WithPathf sets a formatted request path for the `wrapper` instance. +// +// This function constructs a formatted string using the provided format string `v` and arguments `args`, +// assigns the resulting string to the `path` field of the `wrapper`, and returns the modified instance. +// +// Parameters: +// - v: A format string for constructing the request path. +// - args: A variadic list of arguments to be interpolated into the format string. +// +// Returns: +// - A pointer to the modified `wrapper` instance, enabling method chaining. +func (w *wrapper) WithPathf(v string, args ...interface{}) *wrapper { + w.path = fmt.Sprintf(v, args...) + return w +} + // WithHeader sets the header for the `wrapper` instance. // // This function updates the `header` field of the `wrapper` with the provided `header`