mirror of
https://github.com/safing/portbase
synced 2025-09-01 10:09:50 +00:00
37 lines
613 B
Go
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
|
|
}
|