go-hep.org/x/hep@v0.38.1/fwk/ctx.go (about) 1 // Copyright ©2017 The go-hep Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package fwk 6 7 import ( 8 "context" 9 "fmt" 10 ) 11 12 type ctxType struct { 13 id int64 14 slot int 15 store Store 16 msg msgstream 17 mgr App 18 19 ctx context.Context 20 } 21 22 func (ctx ctxType) ID() int64 { 23 return ctx.id 24 } 25 26 func (ctx ctxType) Slot() int { 27 return ctx.slot 28 } 29 30 func (ctx ctxType) Store() Store { 31 return ctx.store 32 } 33 34 func (ctx ctxType) Msg() MsgStream { 35 return ctx.msg 36 } 37 38 func (ctx ctxType) Svc(n string) (Svc, error) { 39 if ctx.mgr == nil { 40 return nil, fmt.Errorf("fwk: no fwk.App available to this Context") 41 } 42 43 svc := ctx.mgr.GetSvc(n) 44 if svc == nil { 45 return nil, fmt.Errorf("fwk: no such service [%s]", n) 46 } 47 return svc, nil 48 }