package asa import ( "errors" "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" ) // GINKey = Standardized keyname to use for storing/accessing *ASA in gin context const GINKey = "asaKey" const defaultLogLevel = logrus.InfoLevel // FromGIN : Returns *ASA from gin context if it exists. Performs checks to attempt to avoid common panic reasons func FromGIN(c *gin.Context) (*ASA, error) { // does it exist? a, ok := c.Get(GINKey) if !ok { return nil, errors.New("ASA.FromGIN(): asa not found in gin context") } // is it the right type? asa, ok := a.(*ASA) if !ok { return nil, errors.New("ASA.FromGIN(): asa in gin context is not of correct type") } return asa, nil } // selectLog : Returns either the passed in logrus logger, or initializes a new one and returns it func selectLog(newLog ...logrus.Ext1FieldLogger) logrus.Ext1FieldLogger { if len(newLog) > 0 { return newLog[0] } else { newLog := logrus.New() newLog.SetLevel(defaultLogLevel) return newLog } }