Admin Interface & Handlers
* In Progress, Not Done Yet + Added Handlers to cover public and admin handlers + Added WebServer + InitHandlers used the new class
This commit is contained in:
parent
f33f7b5c29
commit
c1e8ca4b07
13
Handlers/AddHandler.go
Normal file
13
Handlers/AddHandler.go
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package Handlers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func AddPublicHandler(pattern string, handler func(http.ResponseWriter, *http.Request)) {
|
||||||
|
muxPublic.HandleFunc(pattern, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func AddAdminHandler(pattern string, handler func(http.ResponseWriter, *http.Request)) {
|
||||||
|
muxAdmin.HandleFunc(pattern, handler)
|
||||||
|
}
|
15
Handlers/GetMuxes.go
Normal file
15
Handlers/GetMuxes.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package Handlers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetPublicMux() (mux *http.ServeMux) {
|
||||||
|
mux = muxPublic
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetAdminMux() (mux *http.ServeMux) {
|
||||||
|
mux = muxAdmin
|
||||||
|
return
|
||||||
|
}
|
5
Handlers/Init.go
Normal file
5
Handlers/Init.go
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package Handlers
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
|
||||||
|
}
|
12
Handlers/Variables.go
Normal file
12
Handlers/Variables.go
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package Handlers
|
||||||
|
|
||||||
|
import (
|
||||||
|
LM "github.com/SommerEngineering/Ocean/Log/Meta"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
senderName LM.Sender = `System::Handlers`
|
||||||
|
muxPublic *http.ServeMux = http.NewServeMux()
|
||||||
|
muxAdmin *http.ServeMux = http.NewServeMux()
|
||||||
|
)
|
@ -2,6 +2,7 @@ package System
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/SommerEngineering/Ocean/ConfigurationDB"
|
"github.com/SommerEngineering/Ocean/ConfigurationDB"
|
||||||
|
"github.com/SommerEngineering/Ocean/Handlers"
|
||||||
"github.com/SommerEngineering/Ocean/ICCC"
|
"github.com/SommerEngineering/Ocean/ICCC"
|
||||||
"github.com/SommerEngineering/Ocean/Log"
|
"github.com/SommerEngineering/Ocean/Log"
|
||||||
LM "github.com/SommerEngineering/Ocean/Log/Meta"
|
LM "github.com/SommerEngineering/Ocean/Log/Meta"
|
||||||
@ -9,7 +10,6 @@ import (
|
|||||||
"github.com/SommerEngineering/Ocean/Robots"
|
"github.com/SommerEngineering/Ocean/Robots"
|
||||||
"github.com/SommerEngineering/Ocean/StaticFiles"
|
"github.com/SommerEngineering/Ocean/StaticFiles"
|
||||||
"github.com/SommerEngineering/Ocean/WebContent"
|
"github.com/SommerEngineering/Ocean/WebContent"
|
||||||
"net/http"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitHandlers() {
|
func InitHandlers() {
|
||||||
@ -17,15 +17,15 @@ func InitHandlers() {
|
|||||||
initSystem()
|
initSystem()
|
||||||
Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameSTARTUP, `Register now all system handlers.`)
|
Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameSTARTUP, `Register now all system handlers.`)
|
||||||
|
|
||||||
http.HandleFunc(`/framework/`, WebContent.HandlerDeliverFramework)
|
Handlers.AddPublicHandler(`/framework/`, WebContent.HandlerDeliverFramework)
|
||||||
http.HandleFunc(`/staticFiles/`, StaticFiles.HandlerStaticFiles)
|
Handlers.AddPublicHandler(`/staticFiles/`, StaticFiles.HandlerStaticFiles)
|
||||||
http.HandleFunc(`/next/number`, NumGen.HandlerGetNext)
|
Handlers.AddPublicHandler(`/next/number`, NumGen.HandlerGetNext)
|
||||||
http.HandleFunc(`/robots.txt`, Robots.HandlerRobots)
|
Handlers.AddPublicHandler(`/robots.txt`, Robots.HandlerRobots)
|
||||||
http.HandleFunc(`/ICCC`, ICCC.ICCCHandler)
|
Handlers.AddPublicHandler(`/ICCC`, ICCC.ICCCHandler)
|
||||||
|
|
||||||
if ConfigurationDB.Read(`MapStaticFiles2Root`) == "true" {
|
if ConfigurationDB.Read(`MapStaticFiles2Root`) == "true" {
|
||||||
Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameSTARTUP, `The static files are mapped to the root.`)
|
Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameSTARTUP, `The static files are mapped to the root.`)
|
||||||
http.HandleFunc(`/`, StaticFiles.HandlerMapStaticFiles2Root)
|
Handlers.AddPublicHandler(`/`, StaticFiles.HandlerMapStaticFiles2Root)
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameSTARTUP, `Done with registering all system handler.`)
|
Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameSTARTUP, `Done with registering all system handler.`)
|
||||||
|
@ -1,22 +1,9 @@
|
|||||||
package System
|
package System
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/SommerEngineering/Ocean/ICCC"
|
"github.com/SommerEngineering/Ocean/WebServer"
|
||||||
"github.com/SommerEngineering/Ocean/Log"
|
|
||||||
LM "github.com/SommerEngineering/Ocean/Log/Meta"
|
|
||||||
"github.com/SommerEngineering/Ocean/Tools"
|
|
||||||
"net/http"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func StartAndBlockForever() {
|
func StartAndBlockForever() {
|
||||||
ipAddressPort := Tools.LocalIPAddressAndPort()
|
WebServer.Start()
|
||||||
|
|
||||||
// Tell the whole cluster, that we are up and ready:
|
|
||||||
data := ICCCStartUpMessage{}
|
|
||||||
data.IPAddressAndPort = ipAddressPort
|
|
||||||
ICCC.WriteMessage2All(ICCC.ChannelSYSTEM, `System::Start`, data)
|
|
||||||
|
|
||||||
// Start and block:
|
|
||||||
Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameSTARTUP, `Web server is now listening.`, `Configuration for hostname and port.`, ipAddressPort)
|
|
||||||
http.ListenAndServe(ipAddressPort, nil)
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package System
|
package WebServer
|
||||||
|
|
||||||
type ICCCStartUpMessage struct {
|
type ICCCStartUpMessage struct {
|
||||||
IPAddressAndPort string
|
IPAddressAndPort string
|
34
WebServer/Init.go
Normal file
34
WebServer/Init.go
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package WebServer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/SommerEngineering/Ocean/Handlers"
|
||||||
|
"github.com/SommerEngineering/Ocean/Log"
|
||||||
|
LM "github.com/SommerEngineering/Ocean/Log/Meta"
|
||||||
|
"github.com/SommerEngineering/Ocean/Tools"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
|
||||||
|
Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameSTARTUP, `Init the web server now.`)
|
||||||
|
defer Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameSTARTUP, `Done init the web server.`)
|
||||||
|
|
||||||
|
serverPublicAddressPort := Tools.LocalIPAddressAndPort()
|
||||||
|
|
||||||
|
serverPublic = &http.Server{}
|
||||||
|
serverPublic.Addr = serverPublicAddressPort
|
||||||
|
serverPublic.Handler = Handlers.GetPublicMux()
|
||||||
|
serverPublic.ReadTimeout = 10 * time.Second
|
||||||
|
serverPublic.WriteTimeout = 10 * time.Second
|
||||||
|
serverPublic.MaxHeaderBytes = 1024
|
||||||
|
serverPublic.SetKeepAlivesEnabled(true)
|
||||||
|
|
||||||
|
serverAdmin = &http.Server{}
|
||||||
|
serverAdmin.Addr = serverAdminAddressPort
|
||||||
|
serverAdmin.Handler = Handlers.GetAdminMux()
|
||||||
|
serverAdmin.ReadTimeout = 10 * time.Second
|
||||||
|
serverAdmin.WriteTimeout = 10 * time.Second
|
||||||
|
serverAdmin.MaxHeaderBytes = 1024
|
||||||
|
serverAdmin.SetKeepAlivesEnabled(true)
|
||||||
|
}
|
23
WebServer/Start.go
Normal file
23
WebServer/Start.go
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package WebServer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/SommerEngineering/Ocean/ICCC"
|
||||||
|
"github.com/SommerEngineering/Ocean/Log"
|
||||||
|
LM "github.com/SommerEngineering/Ocean/Log/Meta"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Start() {
|
||||||
|
if serverPublic != nil {
|
||||||
|
// Tell the whole cluster, that we are up and ready:
|
||||||
|
data := ICCCStartUpMessage{}
|
||||||
|
data.IPAddressAndPort = serverPublicAddressPort
|
||||||
|
ICCC.WriteMessage2All(ICCC.ChannelSYSTEM, `System::Start`, data)
|
||||||
|
|
||||||
|
Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameSTARTUP, `Web server is now listening.`, `Configuration for hostname and port.`, serverPublicAddressPort)
|
||||||
|
go serverPublic.ListenAndServe()
|
||||||
|
}
|
||||||
|
|
||||||
|
if serverAdmin != nil {
|
||||||
|
go serverAdmin.ListenAndServe()
|
||||||
|
}
|
||||||
|
}
|
14
WebServer/Variables.go
Normal file
14
WebServer/Variables.go
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package WebServer
|
||||||
|
|
||||||
|
import (
|
||||||
|
LM "github.com/SommerEngineering/Ocean/Log/Meta"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
senderName LM.Sender = `System::WebServer`
|
||||||
|
serverPublic *http.Server = nil
|
||||||
|
serverAdmin *http.Server = nil
|
||||||
|
serverPublicAddressPort string = ""
|
||||||
|
serverAdminAddressPort string = ""
|
||||||
|
)
|
Loading…
Reference in New Issue
Block a user