blob: 4468f08495da989f177e048db7024ad88892bddd [file]
package apiGatewayDeploy
import (
"github.com/30x/apid"
"os"
"path"
)
const (
configBundleDirKey = "gatewaydeploy_bundle_dir"
)
var (
log apid.LogService
db apid.DB
bundlePath string
)
func init() {
apid.RegisterPlugin(initPlugin)
}
func initPlugin(services apid.Services) error {
log = services.Log().ForModule("apiGatewayDeploy")
log.Debug("start init")
config := services.Config()
config.SetDefault(configBundleDirKey, "bundles")
var err error
relativeBundlePath := config.GetString(configBundleDirKey)
if err := os.MkdirAll(relativeBundlePath, 0700); err != nil {
log.Panicf("Failed bundle directory creation: %v", err)
}
storagePath := config.GetString("local_storage_path")
bundlePath = path.Join(storagePath, relativeBundlePath)
log.Infof("Bundle directory path is %s", bundlePath)
db, err = services.Data().DB()
if err != nil {
log.Panic("Unable to access DB", err)
}
initDB()
go distributeEvents()
initAPI(services)
initListener(services)
log.Debug("end init")
return nil
}