github.com/wfusion/gofusion@v1.1.14/config/candy.go (about)

     1  package config
     2  
     3  import (
     4  	"encoding/base64"
     5  
     6  	"github.com/wfusion/gofusion/common/di"
     7  	"github.com/wfusion/gofusion/common/utils"
     8  	"github.com/wfusion/gofusion/common/utils/cipher"
     9  	"github.com/wfusion/gofusion/common/utils/compress"
    10  	"github.com/wfusion/gofusion/common/utils/encode"
    11  )
    12  
    13  func (r *registry) Debug() (debug bool) {
    14  	if r.appName != "" {
    15  		return r.debug
    16  	}
    17  	_ = r.LoadComponentConfig(ComponentDebug, &debug)
    18  	return
    19  }
    20  
    21  func (r *registry) AppName() (name string) {
    22  	if r.appName != "" {
    23  		return r.appName
    24  	}
    25  	_ = r.LoadComponentConfig(ComponentApp, &name)
    26  	return
    27  }
    28  
    29  func (r *registry) DI() di.DI { return r.di }
    30  
    31  func (r *registry) cryptoConfig() (conf *CryptoConf) {
    32  	conf = new(CryptoConf)
    33  	if err := r.LoadComponentConfig(ComponentCrypto, &conf); err != nil {
    34  		return
    35  	}
    36  	parseCfgFunc := func(c *cryptoConf) {
    37  		if c == nil {
    38  			return
    39  		}
    40  		c.Algorithm = cipher.ParseAlgorithm(c.AlgorithmString)
    41  		c.Mode = cipher.ParseMode(c.ModeString)
    42  		c.Key = utils.Must(base64.StdEncoding.DecodeString(c.KeyBase64))
    43  		c.IV = utils.Must(base64.StdEncoding.DecodeString(c.IVBase64))
    44  
    45  		if utils.IsStrPtrNotBlank(c.CompressAlgorithmString) {
    46  			c.CompressAlgorithm = compress.ParseAlgorithm(*c.CompressAlgorithmString)
    47  		}
    48  		if utils.IsStrPtrNotBlank(c.OutputAlgorithmString) {
    49  			c.OutputAlgorithm = encode.ParseAlgorithm(*c.OutputAlgorithmString)
    50  		}
    51  	}
    52  
    53  	if conf != nil {
    54  		parseCfgFunc(conf.Config)
    55  		conf.Custom = make(map[string]*cryptoConf)
    56  		for _, c := range conf.Custom {
    57  			parseCfgFunc(c)
    58  		}
    59  	}
    60  
    61  	return
    62  }