3
0
Files
corteza/app/app.go
2021-10-03 13:57:15 +02:00

84 lines
1.6 KiB
Go

package app
import (
"context"
"net/http"
"github.com/cortezaproject/corteza-server/auth/settings"
"github.com/cortezaproject/corteza-server/pkg/options"
"github.com/cortezaproject/corteza-server/store"
"github.com/go-chi/chi"
"github.com/spf13/cobra"
"go.uber.org/zap"
"google.golang.org/grpc"
)
type (
httpApiServer interface {
MountRoutes(mm ...func(chi.Router))
Serve(ctx context.Context)
}
grpcServer interface {
RegisterServices(func(server *grpc.Server))
Serve(ctx context.Context)
}
wsServer interface {
MountRoutes(chi.Router)
Send(kind string, payload interface{}, userIDs ...uint64) error
}
authServicer interface {
MountHttpRoutes(string, chi.Router)
UpdateSettings(*settings.Settings)
Watch(ctx context.Context)
}
apigwServicer interface {
http.Handler
}
CortezaApp struct {
Opt *options.Options
lvl int
Log *zap.Logger
// Store interface
//
// Just a blank interface{} because we want to avoid generating
// whole store interface (as we do for other packages).
//
// Value will be type-casted when assigned to sys/msg/cmp services
// with warnings when incompatible
Store store.Storer
// CLI Commands
Command *cobra.Command
// Servers
HttpServer httpApiServer
GrpcServer grpcServer
WsServer wsServer
AuthService authServicer
ApigwService apigwServicer
systemEntitiesInitialized bool
}
)
func New() *CortezaApp {
app := &CortezaApp{
lvl: bootLevelWaiting,
Log: zap.NewNop(),
}
app.InitCLI()
return app
}
func (app *CortezaApp) Options() *options.Options {
return app.Opt
}