@@ -1,10 +1,15 @@
|
|||||||
{
|
{
|
||||||
"Host": ":8080",
|
"Host": ":8080",
|
||||||
|
"Encrypted": true,
|
||||||
|
"SSLHost": ":8090",
|
||||||
|
"SSLPrivateKey": "/home/ssl.key",
|
||||||
|
"SSLPublicKey": "/home/ssl.crt",
|
||||||
"Apps": [
|
"Apps": [
|
||||||
{
|
{
|
||||||
"ApplicationDisabled": false,
|
"ApplicationDisabled": false,
|
||||||
"Secret": "7ad3753142a6693b25b9",
|
"Secret": "7ad3753142a6693b25b9",
|
||||||
"Key": "278d525bdf162c739803",
|
"Key": "278d525bdf162c739803",
|
||||||
|
"OnlySSL": false,
|
||||||
"Name": "App 1",
|
"Name": "App 1",
|
||||||
"AppID": "321",
|
"AppID": "321",
|
||||||
"UserEvents": true,
|
"UserEvents": true,
|
||||||
@@ -15,6 +20,7 @@
|
|||||||
"ApplicationDisabled": false,
|
"ApplicationDisabled": false,
|
||||||
"Secret": "d6824d2fa32888931504",
|
"Secret": "d6824d2fa32888931504",
|
||||||
"Key": "c8b30f611ffb13202976",
|
"Key": "c8b30f611ffb13202976",
|
||||||
|
"OnlySSL": false,
|
||||||
"Name": "App 2",
|
"Name": "App 2",
|
||||||
"AppID": "123",
|
"AppID": "123",
|
||||||
"UserEvents": true,
|
"UserEvents": true,
|
||||||
|
|||||||
@@ -14,6 +14,13 @@ type configFile struct {
|
|||||||
Host string // The host, eg: :8080 will start on 0.0.0.0:8080
|
Host string // The host, eg: :8080 will start on 0.0.0.0:8080
|
||||||
User string
|
User string
|
||||||
Password string
|
Password string
|
||||||
|
|
||||||
|
// SSL Configurations
|
||||||
|
Encrypted bool
|
||||||
|
SSLHost string
|
||||||
|
SSLPrivateKey string
|
||||||
|
SSLPublicKey string
|
||||||
|
|
||||||
Apps []*app
|
Apps []*app
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+38
-7
@@ -10,30 +10,61 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/gorilla/mux"
|
||||||
|
log "github.com/golang/glog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Conf holds the global configuration state
|
// Conf holds the global configuration state
|
||||||
var conf configFile
|
var conf configFile
|
||||||
|
|
||||||
|
func Run(conf configFile, router *mux.Router) chan error {
|
||||||
|
|
||||||
|
errs := make(chan error)
|
||||||
|
|
||||||
|
// Starting HTTP server
|
||||||
|
go func() {
|
||||||
|
log.Infof("Staring HTTP service on %s ...", conf.Host)
|
||||||
|
|
||||||
|
if err := http.ListenAndServe(conf.Host, router); err != nil {
|
||||||
|
errs <- err
|
||||||
|
}
|
||||||
|
|
||||||
|
}()
|
||||||
|
|
||||||
|
if conf.Encrypted {
|
||||||
|
// Starting HTTPS server
|
||||||
|
go func() {
|
||||||
|
log.Infof("Staring HTTPS service on %s ...", conf.SSLHost)
|
||||||
|
if err := http.ListenAndServeTLS(conf.SSLHost, conf.SSLPublicKey, conf.SSLPrivateKey, router); err != nil {
|
||||||
|
errs <- err
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
return errs
|
||||||
|
}
|
||||||
|
|
||||||
// Start Parse the configuration file and starts the ipe server
|
// Start Parse the configuration file and starts the ipe server
|
||||||
func Start(configfile string) error {
|
func Start(configfile string) {
|
||||||
rand.Seed(time.Now().Unix())
|
rand.Seed(time.Now().Unix())
|
||||||
file, err := ioutil.ReadFile(configfile)
|
file, err := ioutil.ReadFile(configfile)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := json.Unmarshal(file, &conf); err != nil {
|
if err := json.Unmarshal(file, &conf); err != nil {
|
||||||
return err
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
conf.Init()
|
conf.Init()
|
||||||
router := newRouter()
|
router := newRouter()
|
||||||
|
|
||||||
if err := http.ListenAndServe(conf.Host, router); err != nil {
|
errs := Run(conf, router)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
select {
|
||||||
|
case err := <-errs:
|
||||||
|
log.Errorf("Could not start serving service due to (error: %s)", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/dimiro1/ipe/ipe"
|
"github.com/dimiro1/ipe/ipe"
|
||||||
log "github.com/golang/glog"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Main function, initialze the system
|
// Main function, initialze the system
|
||||||
@@ -19,9 +18,7 @@ func main() {
|
|||||||
|
|
||||||
printBanner()
|
printBanner()
|
||||||
|
|
||||||
if err := ipe.Start(*filename); err != nil {
|
ipe.Start(*filename)
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print a beautifull banner
|
// Print a beautifull banner
|
||||||
|
|||||||
Reference in New Issue
Block a user