...

Source file src/golang.conradwood.net/go-easyops/ctx/query.go

Documentation: golang.conradwood.net/go-easyops/ctx

     1  package ctx
     2  
     3  import (
     4  	"context"
     5  
     6  	ge "golang.conradwood.net/apis/goeasyops"
     7  )
     8  
     9  // get authtags from context
    10  func AuthTags(ctx context.Context) []string {
    11  	ls := GetLocalState(ctx)
    12  	return ls.AuthTags()
    13  }
    14  
    15  // true if context has given authtag
    16  func HasAuthTag(ctx context.Context, tag string) bool {
    17  	ls := GetLocalState(ctx)
    18  	tags := ls.AuthTags()
    19  	for _, t := range tags {
    20  		if tag == t {
    21  			return true
    22  		}
    23  	}
    24  	return false
    25  }
    26  
    27  // get requestid from context
    28  func GetRequestID(ctx context.Context) string {
    29  	ls := GetLocalState(ctx)
    30  	return ls.RequestID()
    31  }
    32  
    33  // get sessionid from context or "" (empty string) if none
    34  func GetSessionID(ctx context.Context) string {
    35  	sess := GetLocalState(ctx).Session()
    36  	if sess == nil {
    37  		return ""
    38  	}
    39  	return sess.SessionID
    40  }
    41  
    42  // get organisationid from context.Session or "" (empty string) if none
    43  func GetOrganisationID(ctx context.Context) string {
    44  	sess := GetLocalState(ctx).Session()
    45  	if sess == nil {
    46  		return ""
    47  	}
    48  	org := sess.Organisation
    49  	if org == nil {
    50  		return ""
    51  	}
    52  	return org.ID
    53  }
    54  
    55  func IsDebug(ctx context.Context) bool {
    56  	ls := GetLocalState(ctx)
    57  	if ls == nil {
    58  		return false
    59  	}
    60  	return ls.Debug()
    61  }
    62  func IsExperimentEnabled(ctx context.Context, name string) bool {
    63  	ls := GetLocalState(ctx)
    64  	if ls == nil {
    65  		return false
    66  	}
    67  	for _, e := range ls.Experiments() {
    68  		if e.Name == name {
    69  			return true
    70  		}
    71  	}
    72  	return false
    73  }
    74  func GetExperiments(ctx context.Context) []*ge.Experiment {
    75  	ls := GetLocalState(ctx)
    76  	if ls == nil {
    77  		return nil
    78  	}
    79  	return ls.Experiments()
    80  }
    81  

View as plain text