From 77422f71f78269c0163059f8ce326b61bd33f544 Mon Sep 17 00:00:00 2001 From: John Guo Date: Sat, 18 Dec 2021 14:10:55 +0800 Subject: [PATCH] add fnction MustSet/MusetSetMap for package gsession --- net/gtrace/internal/provider/provider.go | 10 ++++++++++ os/gsession/gsession_session.go | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/net/gtrace/internal/provider/provider.go b/net/gtrace/internal/provider/provider.go index dd504edae..66a6d80df 100644 --- a/net/gtrace/internal/provider/provider.go +++ b/net/gtrace/internal/provider/provider.go @@ -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( diff --git a/os/gsession/gsession_session.go b/os/gsession/gsession_session.go index 5db11ac7b..a17cb12a4 100644 --- a/os/gsession/gsession_session.go +++ b/os/gsession/gsession_session.go @@ -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)