Not necessary export conf.
This commit is contained in:
+1
-1
@@ -50,7 +50,7 @@ func restAuthenticationHandler(h http.Handler) http.Handler {
|
|||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
appID := vars["app_id"]
|
appID := vars["app_id"]
|
||||||
|
|
||||||
app, err := Conf.GetAppByAppID(appID)
|
app, err := conf.GetAppByAppID(appID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
|
|||||||
+2
-5
@@ -18,9 +18,6 @@ type configFile struct {
|
|||||||
Apps []*app
|
Apps []*app
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error for App not found
|
|
||||||
var AppNotFoundError = errors.New("App not found")
|
|
||||||
|
|
||||||
// Initialize Apps
|
// Initialize Apps
|
||||||
func (c *configFile) Init() {
|
func (c *configFile) Init() {
|
||||||
for _, app := range c.Apps {
|
for _, app := range c.Apps {
|
||||||
@@ -39,7 +36,7 @@ func (c *configFile) GetAppByAppID(appID string) (*app, error) {
|
|||||||
return a, nil
|
return a, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return &app{}, AppNotFoundError
|
return &app{}, errors.New("App not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns an App with by key
|
// Returns an App with by key
|
||||||
@@ -49,5 +46,5 @@ func (c *configFile) GetAppByKey(key string) (*app, error) {
|
|||||||
return a, nil
|
return a, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return &app{}, AppNotFoundError
|
return &app{}, errors.New("App not found")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ func restCheckAppDisabledHandler(h http.Handler) http.Handler {
|
|||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
appID := vars["app_id"]
|
appID := vars["app_id"]
|
||||||
|
|
||||||
currentApp, err := Conf.GetAppByAppID(appID)
|
currentApp, err := conf.GetAppByAppID(appID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, fmt.Sprintf("Could not found an app with app_id: %s", appID), http.StatusForbidden)
|
http.Error(w, fmt.Sprintf("Could not found an app with app_id: %s", appID), http.StatusForbidden)
|
||||||
|
|||||||
+4
-4
@@ -11,7 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Conf holds the global configuration state
|
// Conf holds the global configuration state
|
||||||
var Conf configFile
|
var conf configFile
|
||||||
|
|
||||||
// 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) error {
|
||||||
@@ -21,14 +21,14 @@ func Start(configfile string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := json.Unmarshal(file, &Conf); err != nil {
|
if err := json.Unmarshal(file, &conf); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
Conf.Init()
|
conf.Init()
|
||||||
router := newRouter()
|
router := newRouter()
|
||||||
|
|
||||||
if err := http.ListenAndServe(Conf.Host, router); err != nil {
|
if err := http.ListenAndServe(conf.Host, router); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -33,7 +33,7 @@ func postEvents(w http.ResponseWriter, r *http.Request) {
|
|||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
appID := vars["app_id"]
|
appID := vars["app_id"]
|
||||||
|
|
||||||
app, err := Conf.GetAppByAppID(appID)
|
app, err := conf.GetAppByAppID(appID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, fmt.Sprintf("Could not found an app with app_id: %s", appID), http.StatusBadRequest)
|
http.Error(w, fmt.Sprintf("Could not found an app with app_id: %s", appID), http.StatusBadRequest)
|
||||||
@@ -120,7 +120,7 @@ func getChannels(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
app, err := Conf.GetAppByAppID(appID)
|
app, err := conf.GetAppByAppID(appID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, fmt.Sprintf("Could not found an app with app_id: %s", appID), http.StatusBadRequest)
|
http.Error(w, fmt.Sprintf("Could not found an app with app_id: %s", appID), http.StatusBadRequest)
|
||||||
@@ -183,7 +183,7 @@ func getChannel(w http.ResponseWriter, r *http.Request) {
|
|||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
|
|
||||||
appID := vars["app_id"]
|
appID := vars["app_id"]
|
||||||
app, err := Conf.GetAppByAppID(appID)
|
app, err := conf.GetAppByAppID(appID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, fmt.Sprintf("Could not found an app with app_id: %s", appID), http.StatusBadRequest)
|
http.Error(w, fmt.Sprintf("Could not found an app with app_id: %s", appID), http.StatusBadRequest)
|
||||||
@@ -279,7 +279,7 @@ func getChannelUsers(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
app, err := Conf.GetAppByAppID(appID)
|
app, err := conf.GetAppByAppID(appID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, fmt.Sprintf("Could not found an app with app_id: %s", appID), http.StatusBadRequest)
|
http.Error(w, fmt.Sprintf("Could not found an app with app_id: %s", appID), http.StatusBadRequest)
|
||||||
|
|||||||
+3
-3
@@ -17,12 +17,12 @@ import (
|
|||||||
func newRouter() *mux.Router {
|
func newRouter() *mux.Router {
|
||||||
router := mux.NewRouter().StrictSlash(true)
|
router := mux.NewRouter().StrictSlash(true)
|
||||||
|
|
||||||
if Conf.Expvar {
|
if conf.Expvar {
|
||||||
if !Conf.WasProvidedUserAndPassword() {
|
if !conf.WasProvidedUserAndPassword() {
|
||||||
panic("Your are exporting debug variables and looks like you forget to define an User and a Password")
|
panic("Your are exporting debug variables and looks like you forget to define an User and a Password")
|
||||||
}
|
}
|
||||||
|
|
||||||
router.Handle("/debug/vars", httpauth.SimpleBasicAuth(Conf.User, Conf.Password)(http.DefaultServeMux))
|
router.Handle("/debug/vars", httpauth.SimpleBasicAuth(conf.User, conf.Password)(http.DefaultServeMux))
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, route := range routes {
|
for _, route := range routes {
|
||||||
|
|||||||
+1
-1
@@ -218,7 +218,7 @@ func wsHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
appKey := vars["key"]
|
appKey := vars["key"]
|
||||||
|
|
||||||
app, err := Conf.GetAppByKey(appKey)
|
app, err := conf.GetAppByKey(appKey)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
|
|||||||
Reference in New Issue
Block a user