Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,26 @@ along with Mapo. If not, see <http://www.gnu.org/licenses/>.
Package admin implements the API for Mapo's administration components.
*/
package admin

import (
"gconf/conf"
)

/*
GlobalConfiguration, il oggetto globale per l'accesso ai dati contenuti nel
file di configurazione.
*/
var GlobalConfiguration *conf.ConfigFile

/*
ReadConfiguration, attiva il GlobalConfiguration.
*/
func ReadConfiguration(filepath string) error {

c, err := conf.ReadConfigFile(filepath)
if err == nil {
GlobalConfiguration = c
}

return err
}
Binary file removed log/.log.go.swo
Binary file not shown.
8 changes: 7 additions & 1 deletion log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ var l logger

// SetLevel sets the output level for the global logger
func SetLevel(level int) {
l.level = level

if level <= DEBUG {
l.level = level
return
}

panic(fmt.Sprintf("Unknown log level %v", level))
}

func print(level int, format string, v ...interface{}) {
Expand Down
53 changes: 41 additions & 12 deletions mapo.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,47 @@ along with Mapo. If not, see <http://www.gnu.org/licenses/>.
package main

import (
"mapo/log"
"github.com/maponet/utils/log"
"github.com/maponet/utils/conf"

"flag"
)

func main() {
var err error

// set config defaults
conf.Set("logLevel", "INFO")

// parse flags
var flagLogLevel, flagConfPath string
flag.StringVar(&flagConfPath, "conf", "/etc/mapo/mapo.conf", "set path to configuration file")
flag.StringVar(&flagLogLevel, "log", "", "set loglevel [ERROR|INFO|DEBUG]")
flag.Parse()

// load config from file
confErr := conf.ParseFile(flagConfPath)

// load config and setup application
log.SetLevel(log.DEBUG)
log.Info("Setting log level to DEBUG")
// override config settings with command line flags
if flagLogLevel != "" {
conf.Set("logLevel", flagLogLevel)
}

logLevel, _ := conf.GetString("logLevel")
err = log.SetLevel(logLevel)
if err != nil {
log.Fatal(err.Error())
}

log.Info("Starting application")
if confErr == nil {
log.Info("Loaded configuration file: %s", flagConfPath)
} else {
log.Error("Can't load config file (%s), using defaults", confErr.Error())
}
log.Info("Setting log level to: %s", logLevel)

// setup application

// register with supervisor
log.Info("Joining supervisor")
Expand All @@ -50,20 +80,19 @@ func main() {
// inform supervisor that we are up

// for each request
// check authentication/authorization

// extract request operation
// check authentication/authorization

// extract request arguments
// extract request operation

// pass operation and arguments to api.router
// extract request arguments

// find function mapped to operation
// pass operation and arguments to api.router

// call function with arguments
// find function mapped to operation

// return result to user
// call function with arguments

// return result to user

// close on signal
log.Info("Closing application")
Expand Down