Files
ipe/ipe/ipe.go
T
claudemiro f3dba811b7 Improved Handling SSL
* Panic is betten than using channels in this case
* Changed the names to a more recognized names
* Improved the README with a full config file example
2016-03-03 21:01:21 -03:00

47 lines
1.0 KiB
Go

// Copyright 2015 Claudemiro Alves Feitosa Neto. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package ipe
import (
"encoding/json"
"io/ioutil"
"math/rand"
"net/http"
"time"
log "github.com/golang/glog"
)
// Conf holds the global configuration state
var conf configFile
// Start Parse the configuration file and starts the ipe server
// It Panic if could not start the HTTP or HTTPS server
func Start(configfile string) {
rand.Seed(time.Now().Unix())
file, err := ioutil.ReadFile(configfile)
if err != nil {
log.Fatal(err)
}
if err := json.Unmarshal(file, &conf); err != nil {
log.Fatal(err)
}
conf.Init()
router := newRouter()
if conf.SSL {
go func() {
log.Infof("Starting HTTPS service on %s ...", conf.SSLHost)
log.Fatal(http.ListenAndServeTLS(conf.SSLHost, conf.SSLCertFile, conf.SSLKeyFile, router))
}()
}
log.Infof("Starting HTTP service on %s ...", conf.Host)
log.Fatal(http.ListenAndServe(conf.Host, router))
}