Commit a1b9e647 authored by Sietse Ringers's avatar Sietse Ringers
Browse files

Improve server configuration and error handling

parent 5d5cbb3c
...@@ -22,13 +22,17 @@ func StartRequestorServer(t *testing.T) { ...@@ -22,13 +22,17 @@ func StartRequestorServer(t *testing.T) {
logger.Formatter = &logrus.TextFormatter{} logger.Formatter = &logrus.TextFormatter{}
go func() { go func() {
server.Start(48682, &irmaserver.Configuration{ err := server.Start(&server.Configuration{
Logger: logger, Configuration: &irmaserver.Configuration{
IrmaConfigurationPath: filepath.Join(testdata, "irma_configuration"), Logger: logger,
PrivateKeysPath: filepath.Join(testdata, "privatekeys"), IrmaConfigurationPath: filepath.Join(testdata, "irma_configuration"),
PrivateKeysPath: filepath.Join(testdata, "privatekeys"),
},
Port: 48682,
}) })
require.NoError(t, err)
}() }()
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond) // Give server time to start
} }
func StopRequestorServer(t *testing.T) { func StopRequestorServer(t *testing.T) {
......
...@@ -31,7 +31,10 @@ func main() { ...@@ -31,7 +31,10 @@ func main() {
return return
} }
err = server.Start(port, &irmaserver.Configuration{ err = server.Start(&server.Configuration{
IrmaConfigurationPath: os.Args[2], Configuration: &irmaserver.Configuration{
IrmaConfigurationPath: os.Args[2],
},
Port: port,
}) })
} }
...@@ -12,10 +12,16 @@ import ( ...@@ -12,10 +12,16 @@ import (
"github.com/privacybydesign/irmago/irmaserver/irmarequestor" "github.com/privacybydesign/irmago/irmaserver/irmarequestor"
) )
type Configuration struct {
*irmaserver.Configuration
Port int
}
var server *http.Server var server *http.Server
func Start(port int, conf *irmaserver.Configuration) error { // Start the server. If successful then it will not return until Stop() is called.
if err := irmarequestor.Initialize(conf); err != nil { func Start(conf *Configuration) error {
if err := irmarequestor.Initialize(conf.Configuration); err != nil {
return err return err
} }
...@@ -30,9 +36,12 @@ func Start(port int, conf *irmaserver.Configuration) error { ...@@ -30,9 +36,12 @@ func Start(port int, conf *irmaserver.Configuration) error {
router.Get("/result/{token}", handleResult) router.Get("/result/{token}", handleResult)
// Start server // Start server
server = &http.Server{Addr: fmt.Sprintf(":%d", port), Handler: router} server = &http.Server{Addr: fmt.Sprintf(":%d", conf.Port), Handler: router}
server.ListenAndServe() err := server.ListenAndServe()
return nil if err == http.ErrServerClosed {
return nil // Server was closed normally
}
return err
} }
func Stop() { func Stop() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment