Initial commit of Ocean's local development

This commit is contained in:
Thorsten Sommer committed 2014-04-26 11:18:56 +02:00
1 parent 9944a9e1df
commit 86451938ec
116 files changed
+3320

No files matched your search

+43
View File
@@ -0,0 +1,43 @@
package WebContent
import "errors"
import "archive/zip"
import "io/ioutil"
import "bytes"
import "github.com/SommerEngineering/Ocean/Log"
import LM "github.com/SommerEngineering/Ocean/Log/Meta"
func GetContent(path string) (content []byte, err error) {
reader, readerError := zip.NewReader(bytes.NewReader(zipData), int64(len(zipData)))
if readerError != nil {
err = errors.New("Was not able to read the ZIP file: " + readerError.Error())
Log.LogFull(senderName, LM.CategorySYSTEM, LM.LevelERROR, LM.SeverityCritical, LM.ImpactCritical, LM.MessageNameREAD, `Was not able to read the ZIP file.`, readerError.Error())
return
}
for _, file := range reader.File {
if file.Name == path {
fileReader, openError := file.Open()
defer fileReader.Close()
if openError == nil {
contentData, readError := ioutil.ReadAll(fileReader)
if readError != nil {
err = errors.New("Was not able to read the content of the desired file: " + readError.Error())
Log.LogFull(senderName, LM.CategorySYSTEM, LM.LevelERROR, LM.SeverityCritical, LM.ImpactCritical, LM.MessageNameREAD, `Was not able to read the content of the desired file.`, readError.Error(), path)
return
}
content = contentData
return
}
}
}
err = errors.New("File not found!")
Log.LogFull(senderName, LM.CategorySYSTEM, LM.LevelERROR, LM.SeverityCritical, LM.ImpactCritical, LM.MessageNameNOTFOUND, `The desired file is not part of the ZIP file.`, `Do you use an old version?`, path)
return
}
+22
View File
@@ -0,0 +1,22 @@
package WebContent
import "net/http"
import "strings"
import "github.com/SommerEngineering/Ocean/Shutdown"
import "github.com/SommerEngineering/Ocean/Log"
import LM "github.com/SommerEngineering/Ocean/Log/Meta"
func HandlerDeliverFramework(response http.ResponseWriter, request *http.Request) {
if Shutdown.IsDown() {
http.NotFound(response, request)
return
}
path := strings.Replace(request.URL.Path, "/framework/", "", 1)
sendError := SendContent(response, path)
if sendError != nil {
Log.LogFull(senderName, LM.CategorySYSTEM, LM.LevelERROR, LM.SeverityCritical, LM.ImpactCritical, LM.MessageNameWRITE, `Was not able to send the desired web content file.`, request.URL.Path, sendError.Error())
http.NotFound(response, request)
}
}
+36
View File
@@ -0,0 +1,36 @@
package WebContent
import "io/ioutil"
import "github.com/SommerEngineering/Ocean/CustomerDB"
import "github.com/SommerEngineering/Ocean/ConfigurationDB"
import "github.com/SommerEngineering/Ocean/Log"
import LM "github.com/SommerEngineering/Ocean/Log/Meta"
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.`)
if isInit {
Log.LogFull(senderName, LM.CategorySYSTEM, LM.LevelWARN, LM.SeverityHigh, LM.ImpactNone, LM.MessageNameINIT, `The web content is already fine.`)
return
}
filename = ConfigurationDB.Read(`FilenameWebResources`)
gridFS := CustomerDB.GridFS()
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 {
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
}
+43
View File
@@ -0,0 +1,43 @@
package WebContent
import "net/http"
import "bytes"
import "errors"
import "fmt"
import "github.com/SommerEngineering/Ocean/MimeTypes"
import "github.com/SommerEngineering/Ocean/Log"
import LM "github.com/SommerEngineering/Ocean/Log/Meta"
func SendContent(response http.ResponseWriter, path string) (err error) {
content, contError := GetContent(path)
if contError != nil {
err = errors.New("Was not able to read the needed content: " + contError.Error())
Log.LogFull(senderName, LM.CategorySYSTEM, LM.LevelERROR, LM.SeverityCritical, LM.ImpactCritical, LM.MessageNameREAD, `Was not able to read the needed content.`, contError.Error(), path)
return
}
contentLength := len(content)
contentType, typeError := MimeTypes.DetectType(path)
if typeError != nil {
err = errors.New("Was not able to detect the MIME type: " + typeError.Error())
Log.LogFull(senderName, LM.CategorySYSTEM, LM.LevelERROR, LM.SeverityCritical, LM.ImpactCritical, LM.MessageNameANALYSIS, `Was not able to detect the MIME type for the file.`, path, typeError.Error())
return
}
response.Header().Add("Content-Length", fmt.Sprintf("%d", contentLength))
response.Header().Add("Content-Type", contentType.MimeType)
response.WriteHeader(http.StatusOK)
buffer := bytes.NewBuffer(content)
_, writeError := buffer.WriteTo(response)
if writeError != nil {
err = errors.New("Was not able to write the data to the net: " + writeError.Error())
Log.LogFull(senderName, LM.CategorySYSTEM, LM.LevelERROR, LM.SeverityCritical, LM.ImpactCritical, LM.MessageNameWRITE, `Was not able to write the file to the browser.`, path, writeError.Error())
return
}
return
}
+10
View File
@@ -0,0 +1,10 @@
package WebContent
import LM "github.com/SommerEngineering/Ocean/Log/Meta"
var (
isInit = false
filename = ""
zipData []byte = nil
senderName LM.Sender = `System::WebContent`
)