You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import (
"context""fmt""github.com/kashifkhan0771/utils/ctxutils"
)
funcmain() {
// Create a contextctx:=context.Background()
// Set a string value in contextctx=ctxutils.SetStringValue(ctx, ctxutils.ContextKeyString{"userName"}, "JohnDoe")
// Get the string value from contextuserName, ok:=ctxutils.GetStringValue(ctx, ctxutils.ContextKeyString{"userName"})
ifok {
fmt.Println(userName)
}
}
Output:
JohnDoe
Set and Get a Int Value in Context
package main
import (
"context""fmt""github.com/kashifkhan0771/utils/ctxutils"
)
funcmain() {
// Create a contextctx:=context.Background()
// Set an integer value in contextctx=ctxutils.SetIntValue(ctx, ctxutils.ContextKeyInt{Key: 42}, 100)
// Get the integer value from contextvalue, ok:=ctxutils.GetIntValue(ctx, ctxutils.ContextKeyInt{Key: 42})
ifok {
fmt.Println(value)
}
}