safing-portbase/api/main.go
Daniel 402429cd70 Revamp module structure
- Add shutdown mechanics to module
- Adapt dbmodule to new mechanics
2019-08-09 16:45:43 +02:00

37 lines
613 B
Go

package api
import (
"context"
"errors"
"github.com/safing/portbase/modules"
)
// API Errors
var (
ErrAuthenticationAlreadySet = errors.New("the authentication function has already been set")
)
func init() {
modules.Register("api", prep, start, stop, "base", "database", "config")
}
func prep() error {
if getDefaultListenAddress() == "" {
return errors.New("no listen address for api available")
}
return registerConfig()
}
func start() error {
logFlagOverrides()
go Serve()
return nil
}
func stop() error {
if server != nil {
return server.Shutdown(context.Background())
}
return nil
}