mirror of
https://github.com/ManyakRus/starter.git
synced 2025-11-26 23:10:42 +02:00
сделал contextmain.SetContext(ctx)
This commit is contained in:
@@ -257,7 +257,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup, HandleJob func(c
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
//запомним к себе контекст
|
//запомним к себе контекст
|
||||||
contextmain.Ctx = ctx
|
if contextmain.Ctx != ctx {
|
||||||
|
contextmain.SetContext(ctx)
|
||||||
|
}
|
||||||
|
//contextmain.Ctx = ctx
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
contextmain.GetContext()
|
contextmain.GetContext()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -217,7 +217,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup, HandleJob func(c
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
//запомним к себе контекст
|
//запомним к себе контекст
|
||||||
contextmain.Ctx = ctx
|
if contextmain.Ctx != ctx {
|
||||||
|
contextmain.SetContext(ctx)
|
||||||
|
}
|
||||||
|
//contextmain.Ctx = ctx
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
contextmain.GetContext()
|
contextmain.GetContext()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -163,7 +163,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup) error {
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
//запомним к себе контекст
|
//запомним к себе контекст
|
||||||
contextmain.Ctx = ctx
|
if contextmain.Ctx != ctx {
|
||||||
|
contextmain.SetContext(ctx)
|
||||||
|
}
|
||||||
|
//contextmain.Ctx = ctx
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
contextmain.GetContext()
|
contextmain.GetContext()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -159,7 +159,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup) error {
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
//запомним к себе контекст
|
//запомним к себе контекст
|
||||||
contextmain.Ctx = ctx
|
if contextmain.Ctx != ctx {
|
||||||
|
contextmain.SetContext(ctx)
|
||||||
|
}
|
||||||
|
//contextmain.Ctx = ctx
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
contextmain.GetContext()
|
contextmain.GetContext()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,24 +18,26 @@ var CancelContext func()
|
|||||||
// onceCtx - гарантирует единственное создание контеста
|
// onceCtx - гарантирует единственное создание контеста
|
||||||
var onceCtx sync.Once
|
var onceCtx sync.Once
|
||||||
|
|
||||||
// lockContextMain - гарантирует единственное создание контеста
|
// MutexContextMain - гарантирует единственное создание контеста
|
||||||
// var lockContextMain sync.Mutex
|
var MutexContextMain sync.RWMutex
|
||||||
|
|
||||||
// GetContext - возвращает глобальный контекст приложения
|
// GetContext - возвращает глобальный контекст приложения
|
||||||
func GetContext() context.Context {
|
func GetContext() context.Context {
|
||||||
//lockContextMain.Lock()
|
MutexContextMain.RLock()
|
||||||
//defer lockContextMain.Unlock()
|
defer MutexContextMain.RUnlock()
|
||||||
//
|
|
||||||
//if Ctx == nil {
|
//if Ctx == nil {
|
||||||
// CtxBg := context.Background()
|
// CtxBg := context.Background()
|
||||||
// Ctx, CancelContext = context.WithCancel(CtxBg)
|
// Ctx, CancelContext = context.WithCancel(CtxBg)
|
||||||
//}
|
//}
|
||||||
|
|
||||||
onceCtx.Do(func() {
|
onceCtx.Do(func() {
|
||||||
|
if Ctx == nil { //можно заполнить свой контекст, поэтому if
|
||||||
CtxBg := context.Background()
|
CtxBg := context.Background()
|
||||||
var Ctx0 context.Context
|
var Ctx0 context.Context
|
||||||
Ctx0, CancelContext = context.WithCancel(CtxBg)
|
Ctx0, CancelContext = context.WithCancel(CtxBg)
|
||||||
Ctx = &Ctx0
|
Ctx = &Ctx0
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return *Ctx
|
return *Ctx
|
||||||
@@ -50,3 +52,17 @@ func GetNewContext() context.Context {
|
|||||||
|
|
||||||
return *Ctx
|
return *Ctx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetContext - устанавливает глобальный контекст, с учётом Mutex
|
||||||
|
func SetContext(ctx *context.Context) {
|
||||||
|
MutexContextMain.Lock()
|
||||||
|
defer MutexContextMain.Unlock()
|
||||||
|
Ctx = ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCancelContext - устанавливает функцию глобального отмены контекста, с учётом Mutex
|
||||||
|
func SetCancelContext(cancelContext func()) {
|
||||||
|
MutexContextMain.Lock()
|
||||||
|
defer MutexContextMain.Unlock()
|
||||||
|
CancelContext = cancelContext
|
||||||
|
}
|
||||||
|
|||||||
@@ -259,7 +259,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup) error {
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
//запомним к себе контекст
|
//запомним к себе контекст
|
||||||
contextmain.Ctx = ctx
|
if contextmain.Ctx != ctx {
|
||||||
|
contextmain.SetContext(ctx)
|
||||||
|
}
|
||||||
|
//contextmain.Ctx = ctx
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
contextmain.GetContext()
|
contextmain.GetContext()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -289,7 +289,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup) error {
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
//запомним к себе контекст
|
//запомним к себе контекст
|
||||||
contextmain.Ctx = ctx
|
if contextmain.Ctx != ctx {
|
||||||
|
contextmain.SetContext(ctx)
|
||||||
|
}
|
||||||
|
//contextmain.Ctx = ctx
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
contextmain.GetContext()
|
contextmain.GetContext()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -145,7 +145,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup) {
|
|||||||
//var err error
|
//var err error
|
||||||
|
|
||||||
//запомним к себе контекст
|
//запомним к себе контекст
|
||||||
contextmain.Ctx = ctx
|
if contextmain.Ctx != ctx {
|
||||||
|
contextmain.SetContext(ctx)
|
||||||
|
}
|
||||||
|
//contextmain.Ctx = ctx
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
contextmain.GetContext()
|
contextmain.GetContext()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,7 +120,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup) error {
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
//запомним к себе контекст
|
//запомним к себе контекст
|
||||||
contextmain.Ctx = ctx
|
if contextmain.Ctx != ctx {
|
||||||
|
contextmain.SetContext(ctx)
|
||||||
|
}
|
||||||
|
//contextmain.Ctx = ctx
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
contextmain.GetContext()
|
contextmain.GetContext()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup) {
|
|||||||
//var err error
|
//var err error
|
||||||
|
|
||||||
//запомним к себе контекст
|
//запомним к себе контекст
|
||||||
contextmain.Ctx = ctx
|
if contextmain.Ctx != ctx {
|
||||||
|
contextmain.SetContext(ctx)
|
||||||
|
}
|
||||||
|
//contextmain.Ctx = ctx
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
contextmain.GetContext()
|
contextmain.GetContext()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -217,7 +217,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup) error {
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
//запомним к себе контекст
|
//запомним к себе контекст
|
||||||
contextmain.Ctx = ctx
|
if contextmain.Ctx != ctx {
|
||||||
|
contextmain.SetContext(ctx)
|
||||||
|
}
|
||||||
|
//contextmain.Ctx = ctx
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
contextmain.GetContext()
|
contextmain.GetContext()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -223,7 +223,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup) error {
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
//запомним к себе контекст
|
//запомним к себе контекст
|
||||||
contextmain.Ctx = ctx
|
if contextmain.Ctx != ctx {
|
||||||
|
contextmain.SetContext(ctx)
|
||||||
|
}
|
||||||
|
//contextmain.Ctx = ctx
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
contextmain.GetContext()
|
contextmain.GetContext()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -237,7 +237,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup) error {
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
//запомним к себе контекст
|
//запомним к себе контекст
|
||||||
contextmain.Ctx = ctx
|
if contextmain.Ctx != ctx {
|
||||||
|
contextmain.SetContext(ctx)
|
||||||
|
}
|
||||||
|
//contextmain.Ctx = ctx
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
contextmain.GetContext()
|
contextmain.GetContext()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,7 +88,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup, ServiceName stri
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
//запомним к себе контекст
|
//запомним к себе контекст
|
||||||
contextmain.Ctx = ctx
|
if contextmain.Ctx != ctx {
|
||||||
|
contextmain.SetContext(ctx)
|
||||||
|
}
|
||||||
|
//contextmain.Ctx = ctx
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
contextmain.GetContext()
|
contextmain.GetContext()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -212,7 +212,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup, ServiceName stri
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
//запомним к себе контекст
|
//запомним к себе контекст
|
||||||
contextmain.Ctx = ctx
|
if contextmain.Ctx != ctx {
|
||||||
|
contextmain.SetContext(ctx)
|
||||||
|
}
|
||||||
|
//contextmain.Ctx = ctx
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
contextmain.GetContext()
|
contextmain.GetContext()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -235,7 +235,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup) error {
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
//запомним к себе контекст
|
//запомним к себе контекст
|
||||||
contextmain.Ctx = ctx
|
if contextmain.Ctx != ctx {
|
||||||
|
contextmain.SetContext(ctx)
|
||||||
|
}
|
||||||
|
//contextmain.Ctx = ctx
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
contextmain.GetContext()
|
contextmain.GetContext()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -295,7 +295,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup) error {
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
//запомним к себе контекст
|
//запомним к себе контекст
|
||||||
contextmain.Ctx = ctx
|
if contextmain.Ctx != ctx {
|
||||||
|
contextmain.SetContext(ctx)
|
||||||
|
}
|
||||||
|
//contextmain.Ctx = ctx
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
contextmain.GetContext()
|
contextmain.GetContext()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -297,7 +297,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup) error {
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
//запомним к себе контекст
|
//запомним к себе контекст
|
||||||
contextmain.Ctx = ctx
|
if contextmain.Ctx != ctx {
|
||||||
|
contextmain.SetContext(ctx)
|
||||||
|
}
|
||||||
|
//contextmain.Ctx = ctx
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
contextmain.GetContext()
|
contextmain.GetContext()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -266,7 +266,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup) error {
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
//запомним к себе контекст
|
//запомним к себе контекст
|
||||||
contextmain.Ctx = ctx
|
if contextmain.Ctx != ctx {
|
||||||
|
contextmain.SetContext(ctx)
|
||||||
|
}
|
||||||
|
//contextmain.Ctx = ctx
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
contextmain.GetContext()
|
contextmain.GetContext()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -293,7 +293,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup, Connection conne
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
//запомним к себе контекст
|
//запомним к себе контекст
|
||||||
contextmain.Ctx = ctx
|
if contextmain.Ctx != ctx {
|
||||||
|
contextmain.SetContext(ctx)
|
||||||
|
}
|
||||||
|
//contextmain.Ctx = ctx
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
contextmain.GetContext()
|
contextmain.GetContext()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup, ServiceName, Ser
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
//запомним к себе контекст
|
//запомним к себе контекст
|
||||||
contextmain.Ctx = ctx
|
if contextmain.Ctx != ctx {
|
||||||
|
contextmain.SetContext(ctx)
|
||||||
|
}
|
||||||
|
//contextmain.Ctx = ctx
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
contextmain.GetContext()
|
contextmain.GetContext()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -264,7 +264,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup) error {
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
//запомним к себе контекст
|
//запомним к себе контекст
|
||||||
contextmain.Ctx = ctx
|
if contextmain.Ctx != ctx {
|
||||||
|
contextmain.SetContext(ctx)
|
||||||
|
}
|
||||||
|
//contextmain.Ctx = ctx
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
contextmain.GetContext()
|
contextmain.GetContext()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -854,7 +854,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup, func_OnNewMessag
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
//запомним к себе контекст
|
//запомним к себе контекст
|
||||||
contextmain.Ctx = ctx
|
if contextmain.Ctx != ctx {
|
||||||
|
contextmain.SetContext(ctx)
|
||||||
|
}
|
||||||
|
//contextmain.Ctx = ctx
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
contextmain.GetContext()
|
contextmain.GetContext()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,7 +155,10 @@ func Start() {
|
|||||||
// wg - глобальный WaitGroup приложения
|
// wg - глобальный WaitGroup приложения
|
||||||
func Start_ctx(ctx *context.Context, wg *sync.WaitGroup) error {
|
func Start_ctx(ctx *context.Context, wg *sync.WaitGroup) error {
|
||||||
var err error
|
var err error
|
||||||
contextmain.Ctx = ctx
|
if contextmain.Ctx != ctx {
|
||||||
|
contextmain.SetContext(ctx)
|
||||||
|
}
|
||||||
|
//contextmain.Ctx = ctx
|
||||||
stopapp.SetWaitGroup_Main(wg)
|
stopapp.SetWaitGroup_Main(wg)
|
||||||
|
|
||||||
err = Connect_err()
|
err = Connect_err()
|
||||||
|
|||||||
@@ -327,7 +327,10 @@ func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup, eventHandler fun
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
//запомним к себе контекст
|
//запомним к себе контекст
|
||||||
contextmain.Ctx = ctx
|
if contextmain.Ctx != ctx {
|
||||||
|
contextmain.SetContext(ctx)
|
||||||
|
}
|
||||||
|
//contextmain.Ctx = ctx
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
contextmain.GetContext()
|
contextmain.GetContext()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user