Skip to content
Snippets Groups Projects
Select Git revision
  • 0625050fd0ba35b836bacf19da999b0eb34308c1
  • master default protected
  • refactor/PRXS-3053-Files
  • feature/PRXS-3143-3235-ReferenceOptions
  • feature/PRXS-3421-ImplementNewRefAPI
  • feature/PRXS-3143-LimitReferenceFields
  • feature/PRXS-3234-FeaturePruneIdents
  • feature/3149-LocaleCodeAsID-Feature
  • feature/PRXS-3383-CollectionsRankSortAPI
  • PRXS-3421-RecursiveReferences
  • feature/PRXS-3383-CollectionsSort
  • feature/3109-SerializeFeature
  • release/0.33
  • feature/3109-RecoverySchema
  • feature/3109-feature
  • fix/PRXS-3369-ValidateFields
  • refactor/PRXS-3306-MovePkgGroup1
  • refactor/6-pkg-refactor-expr
  • fix/PRXS-3360-TemplateBuilderPatch
  • feature/3293-MongoV2
  • feature/3272-GoVersionUp
  • v0.33.1
  • v0.32.0
  • v0.31.1
  • v0.31.0
  • v0.30.0
  • v0.29.0
  • v0.28.0
  • v0.27.0-alpha.1+16
  • v0.27.0-alpha.1+15
  • v0.27.0-alpha.1+14
  • v0.27.0-alpha.1+13
  • v0.27.0-alpha.1+12
  • v0.27.0-alpha.1+11
  • v0.27.0-alpha.1+10
  • v0.27.0-alpha.1+9
  • v0.27.0-alpha.1+8
  • v0.27.0-alpha.1+7
  • v0.27.0-alpha.1+6
  • v0.27.0-alpha.1+5
  • v0.27.0-alpha.1+4
41 results

caching_middleware_test.go

Blame
  • context.go 1.40 KiB
    package items
    
    import (
    	"context"
    
    	"git.perx.ru/perxis/perxis-go/pkg/clients"
    	"git.perx.ru/perxis/perxis-go/pkg/environments"
    	"git.perx.ru/perxis/perxis-go/pkg/spaces"
    )
    
    type Context struct {
    	Items
    	Clients clients.Clients
    
    	SpaceID      string
    	EnvID        string
    	CollectionID string
    	ItemID       string
    	Item         *Item
    	Space        *spaces.Space
    	Environment  *environments.Environment
    
    	ViewSpaceID       string
    	ViewEnvironmentID string
    	ViewCollectionID  string
    	ViewSpace         *spaces.Space
    	ViewEnvironment   *environments.Environment
    }
    
    type itemsCtx struct{}
    
    func WithContext(ctx context.Context, itmCtx *Context) context.Context {
    	if ctx == nil {
    		ctx = context.Background()
    	}
    
    	if itmCtx.ViewSpaceID == "" {
    		itmCtx.ViewSpaceID = itmCtx.SpaceID
    	}
    	if itmCtx.ViewEnvironmentID == "" {
    		itmCtx.ViewEnvironmentID = itmCtx.EnvID
    	}
    	if itmCtx.ViewCollectionID == "" {
    		itmCtx.ViewCollectionID = itmCtx.CollectionID
    	}
    	if itmCtx.ViewSpace == nil {
    		itmCtx.ViewSpace = itmCtx.Space
    	}
    	if itmCtx.ViewEnvironment == nil {
    		itmCtx.ViewEnvironment = itmCtx.Environment
    	}
    
    	p, _ := ctx.Value(itemsCtx{}).(*Context)
    	if p != nil {
    		*p = *itmCtx
    		return ctx
    	}
    
    	return context.WithValue(ctx, itemsCtx{}, itmCtx)
    }
    
    func GetContext(ctx context.Context) *Context {
    	if ctx == nil {
    		return new(Context)
    	}
    	p, _ := ctx.Value(itemsCtx{}).(*Context)
    	if p == nil {
    		return new(Context)
    	}
    	return p
    }