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) {
logger.Formatter = &logrus.TextFormatter{}
go func() {
server.Start(48682, &irmaserver.Configuration{
Logger: logger,
IrmaConfigurationPath: filepath.Join(testdata, "irma_configuration"),
PrivateKeysPath: filepath.Join(testdata, "privatekeys"),
err := server.Start(&server.Configuration{
Configuration: &irmaserver.Configuration{
Logger: logger,
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) {
......
......@@ -31,7 +31,10 @@ func main() {
return
}
err = server.Start(port, &irmaserver.Configuration{
IrmaConfigurationPath: os.Args[2],
err = server.Start(&server.Configuration{
Configuration: &irmaserver.Configuration{
IrmaConfigurationPath: os.Args[2],
},
Port: port,
})
}
......@@ -12,10 +12,16 @@ import (
"github.com/privacybydesign/irmago/irmaserver/irmarequestor"
)
type Configuration struct {
*irmaserver.Configuration
Port int
}
var server *http.Server
func Start(port int, conf *irmaserver.Configuration) error {
if err := irmarequestor.Initialize(conf); err != nil {
// Start the server. If successful then it will not return until Stop() is called.
func Start(conf *Configuration) error {
if err := irmarequestor.Initialize(conf.Configuration); err != nil {
return err
}
......@@ -30,9 +36,12 @@ func Start(port int, conf *irmaserver.Configuration) error {
router.Get("/result/{token}", handleResult)
// Start server
server = &http.Server{Addr: fmt.Sprintf(":%d", port), Handler: router}
server.ListenAndServe()
return nil
server = &http.Server{Addr: fmt.Sprintf(":%d", conf.Port), Handler: router}
err := server.ListenAndServe()
if err == http.ErrServerClosed {
return nil // Server was closed normally
}
return err
}
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