CreateAppBasicRes returns an application level BasicRes instance based on .env/environment variables it is useful because multiple places need BasicRes including `main.go` `directrun` and `worker` keep in mind this function can be called only once
()
| 37 | // it is useful because multiple places need BasicRes including `main.go` `directrun` and `worker` |
| 38 | // keep in mind this function can be called only once |
| 39 | func CreateAppBasicRes() context.BasicRes { |
| 40 | app_lock.Lock() |
| 41 | if app_inited { |
| 42 | panic(fmt.Errorf("CreateAppBasicRes can be called once")) |
| 43 | } |
| 44 | app_inited = true |
| 45 | app_lock.Unlock() |
| 46 | cfg := config.GetConfig() |
| 47 | logger := logruslog.Global |
| 48 | db, err := NewGormDb(cfg, logger) |
| 49 | if err != nil { |
| 50 | panic(err) |
| 51 | } |
| 52 | dalgorm.Init(cfg.GetString(plugin.EncodeKeyEnvStr)) |
| 53 | return CreateBasicRes(cfg, logger, db) |
| 54 | } |
| 55 | |
| 56 | // CreateBasicRes returns a BasicRes based on what was given |
| 57 | func CreateBasicRes(cfg config.ConfigReader, logger log.Logger, db *gorm.DB) context.BasicRes { |