2014-04-26 09:18:56 +00:00
package WebContent
2014-10-19 17:19:11 +00:00
import (
"github.com/SommerEngineering/Ocean/ConfigurationDB"
"github.com/SommerEngineering/Ocean/CustomerDB"
"github.com/SommerEngineering/Ocean/Log"
LM "github.com/SommerEngineering/Ocean/Log/Meta"
"io/ioutil"
)
2014-04-26 09:18:56 +00:00
2015-06-17 15:44:52 +00:00
/ *
Init the web content package . It is used to provided some static data for web
frameworks like e . g . jQuery , d3 . js , Bootstrap , etc .
* /
2014-04-26 09:18:56 +00:00
func init ( ) {
Log . LogShort ( senderName , LM . CategorySYSTEM , LM . LevelINFO , LM . MessageNameINIT , ` Run init for the web content. ` )
defer Log . LogShort ( senderName , LM . CategorySYSTEM , LM . LevelINFO , LM . MessageNameINIT , ` Init for web content done. ` )
2015-06-17 15:44:52 +00:00
// Ensure that we init this package only once:
2014-04-26 09:18:56 +00:00
if isInit {
Log . LogFull ( senderName , LM . CategorySYSTEM , LM . LevelWARN , LM . SeverityHigh , LM . ImpactNone , LM . MessageNameINIT , ` The web content is already fine. ` )
return
}
2015-06-17 15:44:52 +00:00
// Get the filename out of the database:
2014-04-26 09:18:56 +00:00
filename = ConfigurationDB . Read ( ` FilenameWebResources ` )
2014-06-04 19:41:18 +00:00
dbSession , gridFS := CustomerDB . GridFS ( )
defer dbSession . Close ( )
2014-04-26 09:18:56 +00:00
2015-06-17 15:44:52 +00:00
// Open the file out of the grid file system:
2014-04-26 09:18:56 +00:00
if gridFile , errGridFile := gridFS . Open ( filename ) ; errGridFile != nil {
Log . LogFull ( senderName , LM . CategorySYSTEM , LM . LevelERROR , LM . SeverityCritical , LM . ImpactCritical , LM . MessageNameDATABASE , ` Was not able to open the web content out of the GridFS! ` , filename , errGridFile . Error ( ) )
return
} else {
2015-06-17 15:44:52 +00:00
// Read all the data in the memeory cache:
2014-04-26 09:18:56 +00:00
defer gridFile . Close ( )
if data , ioError := ioutil . ReadAll ( gridFile ) ; ioError != nil {
Log . LogFull ( senderName , LM . CategorySYSTEM , LM . LevelERROR , LM . SeverityCritical , LM . ImpactCritical , LM . MessageNameDATABASE , ` Was not able to read the web content file. ` , filename , ioError . Error ( ) )
return
} else {
zipData = data
}
}
return
}