add fnction MustSet/MusetSetMap for package gsession

This commit is contained in:
John Guo 2021-12-18 14:10:55 +08:00
parent 40225c5352
commit 77422f71f7
2 changed files with 26 additions and 0 deletions

View File

@ -14,6 +14,16 @@ type TracerProvider struct {
*sdkTrace.TracerProvider
}
// New returns a new and configured TracerProvider, which has no SpanProcessor.
//
// In default the returned TracerProvider is configured with:
// - a ParentBased(AlwaysSample) Sampler
// - a unix nano timestamp and random umber based IDGenerator
// - the resource.Default() Resource
// - the default SpanLimits.
//
// The passed opts are used to override these default values and configure the
// returned TracerProvider appropriately.
func New() *TracerProvider {
return &TracerProvider{
TracerProvider: sdkTrace.NewTracerProvider(

View File

@ -306,6 +306,22 @@ func (s *Session) MustGet(key string, def ...interface{}) *gvar.Var {
return v
}
// MustSet performs as function Set, but it panics if any error occurs.
func (s *Session) MustSet(key string, value interface{}) {
err := s.Set(key, value)
if err != nil {
panic(err)
}
}
// MustSetMap performs as function SetMap, but it panics if any error occurs.
func (s *Session) MustSetMap(data map[string]interface{}) {
err := s.SetMap(data)
if err != nil {
panic(err)
}
}
// MustContains performs as function Contains, but it panics if any error occurs.
func (s *Session) MustContains(key string) bool {
b, err := s.Contains(key)