Cleanup internal, vendors, cleanup cmd/*
Introduces /pkg for non-intenral packages
This commit is contained in:
+7
-59
@@ -1,69 +1,17 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
context "github.com/SentimensRG/ctx"
|
||||
"github.com/SentimensRG/ctx/sigctx"
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
"github.com/namsral/flag"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
|
||||
compose "github.com/crusttech/crust/compose"
|
||||
"github.com/crusttech/crust/internal/logger"
|
||||
"github.com/crusttech/crust/internal/subscription"
|
||||
system "github.com/crusttech/crust/system"
|
||||
"github.com/cortezaproject/corteza-server/compose"
|
||||
"github.com/cortezaproject/corteza-server/pkg/cli"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Initialize default logger
|
||||
logger.Init(zapcore.DebugLevel)
|
||||
log := logger.Default().Named("compose")
|
||||
|
||||
// New signal-bond context that we will use and
|
||||
// will get terminated (Done()) on SIGINT or SIGTERM
|
||||
ctx := context.AsContext(sigctx.New())
|
||||
|
||||
// Bind default logger to context
|
||||
ctx = logger.ContextWithValue(ctx, log)
|
||||
|
||||
compose.Flags("compose")
|
||||
system.Flags("system")
|
||||
|
||||
subscription.Flags()
|
||||
|
||||
flag.Parse()
|
||||
|
||||
if err := system.Init(ctx); err != nil {
|
||||
log.Fatal("failed to initialize system", zap.Error(err))
|
||||
}
|
||||
if err := compose.Init(ctx); err != nil {
|
||||
log.Fatal("failed to initialize compose", zap.Error(err))
|
||||
}
|
||||
|
||||
var command string
|
||||
if len(os.Args) > 1 {
|
||||
command = os.Args[1]
|
||||
}
|
||||
|
||||
switch command {
|
||||
case "help":
|
||||
flag.PrintDefaults()
|
||||
case "provision":
|
||||
if err := compose.Provision(ctx); err != nil {
|
||||
println("Failed to provision compose: ", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
default:
|
||||
// Checks subscription, will os.Exit(1) if there is an error
|
||||
// Disabled for now, system service is the only one that validates subscription
|
||||
// ctx = subscription.Monitor(ctx)
|
||||
|
||||
compose.StartWatchers(ctx)
|
||||
|
||||
if err := compose.StartRestAPI(ctx); err != nil {
|
||||
log.Fatal("failed to start compose REST API", zap.Error(err))
|
||||
}
|
||||
c := compose.InitCompose()
|
||||
if err := c.Command(cli.Context()).Execute(); err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,159 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
context "github.com/SentimensRG/ctx"
|
||||
"github.com/SentimensRG/ctx/sigctx"
|
||||
"github.com/go-chi/chi"
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
"github.com/namsral/flag"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
|
||||
compose "github.com/crusttech/crust/compose"
|
||||
"github.com/crusttech/crust/internal/auth"
|
||||
"github.com/crusttech/crust/internal/logger"
|
||||
messaging "github.com/crusttech/crust/messaging"
|
||||
system "github.com/crusttech/crust/system"
|
||||
|
||||
"github.com/crusttech/crust/internal/config"
|
||||
"github.com/crusttech/crust/internal/metrics"
|
||||
"github.com/crusttech/crust/internal/middleware"
|
||||
"github.com/crusttech/crust/internal/subscription"
|
||||
)
|
||||
|
||||
// Serves index.html in case the requested file isn't found (or some other os.Stat error)
|
||||
func serveIndex(assetPath string, indexPath string, serve http.Handler) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
indexPage := path.Join(assetPath, indexPath)
|
||||
requestedPage := path.Join(assetPath, r.URL.Path)
|
||||
_, err := os.Stat(requestedPage)
|
||||
if err != nil {
|
||||
http.ServeFile(w, r, indexPage)
|
||||
return
|
||||
}
|
||||
serve.ServeHTTP(w, r)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Initialize default logger
|
||||
logger.Init(zapcore.DebugLevel)
|
||||
log := logger.Default().Named("crust")
|
||||
|
||||
// New signal-bond context that we will use and
|
||||
// will get terminated (Done()) on SIGINT or SIGTERM
|
||||
ctx := context.AsContext(sigctx.New())
|
||||
|
||||
// Bind default logger to context
|
||||
ctx = logger.ContextWithValue(ctx, log)
|
||||
|
||||
var flags struct {
|
||||
http *config.HTTP
|
||||
monitor *config.Monitor
|
||||
}
|
||||
|
||||
flags.http = new(config.HTTP).Init()
|
||||
flags.monitor = new(config.Monitor).Init()
|
||||
|
||||
compose.Flags("compose")
|
||||
messaging.Flags("messaging")
|
||||
system.Flags("system")
|
||||
|
||||
authJwtFlags := new(config.JWT).Init()
|
||||
|
||||
subscription.Flags()
|
||||
|
||||
flag.Parse()
|
||||
|
||||
var command string
|
||||
if len(os.Args) > 1 {
|
||||
command = os.Args[1]
|
||||
}
|
||||
|
||||
switch command {
|
||||
case "help":
|
||||
flag.PrintDefaults()
|
||||
|
||||
case "provision":
|
||||
if err := system.Provision(ctx); err != nil {
|
||||
println("Failed to provision system: ", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
if err := compose.Provision(ctx); err != nil {
|
||||
println("Failed to provision compose: ", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
if err := messaging.Provision(ctx); err != nil {
|
||||
println("Failed to provision messaging: ", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
default:
|
||||
// Initialize configuration of our services
|
||||
if err := system.Init(ctx); err != nil {
|
||||
log.Fatal("failed to initialize system", zap.Error(err))
|
||||
}
|
||||
if err := compose.Init(ctx); err != nil {
|
||||
log.Fatal("failed to initialize compose", zap.Error(err))
|
||||
}
|
||||
if err := messaging.Init(ctx); err != nil {
|
||||
log.Fatal("failed to initialize messaging", zap.Error(err))
|
||||
}
|
||||
// Checks subscription, will os.Exit(1) if there is an error
|
||||
// Disabled for now, system service is the only one that validates subscription
|
||||
// ctx = subscription.Monitor(ctx)
|
||||
|
||||
log.Info("Starting http server on address " + flags.http.Addr)
|
||||
listener, err := net.Listen("tcp", flags.http.Addr)
|
||||
if err != nil {
|
||||
log.Info("Can't listen on addr " + flags.http.Addr)
|
||||
}
|
||||
|
||||
if flags.monitor.Interval > 0 {
|
||||
go metrics.NewMonitor(flags.monitor.Interval)
|
||||
}
|
||||
|
||||
system.StartWatchers(ctx)
|
||||
compose.StartWatchers(ctx)
|
||||
messaging.StartWatchers(ctx)
|
||||
|
||||
r := chi.NewRouter()
|
||||
|
||||
// logging, cors and such
|
||||
middleware.Mount(ctx, r, flags.http)
|
||||
|
||||
// Use JWT secret for hmac signer for now
|
||||
auth.DefaultSigner = auth.HmacSigner(authJwtFlags.Secret)
|
||||
auth.DefaultJwtHandler, err = auth.JWT(authJwtFlags.Secret, authJwtFlags.Expiry)
|
||||
if err != nil {
|
||||
log.Fatal("Error creating JWT Auth", zap.Error(err))
|
||||
}
|
||||
|
||||
r.Route("/api", func(r chi.Router) {
|
||||
r.Route("/compose", func(r chi.Router) {
|
||||
compose.MountRoutes(ctx, r)
|
||||
})
|
||||
r.Route("/messaging", func(r chi.Router) {
|
||||
messaging.MountRoutes(ctx, r)
|
||||
})
|
||||
r.Route("/system", func(r chi.Router) {
|
||||
system.MountRoutes(ctx, r)
|
||||
})
|
||||
middleware.MountSystemRoutes(ctx, r, flags.http)
|
||||
})
|
||||
|
||||
fileserver := http.FileServer(http.Dir("webapp"))
|
||||
|
||||
for _, service := range []string{"admin", "auth", "messaging", "compose"} {
|
||||
r.HandleFunc("/"+service+"*", serveIndex("webapp", "compose/index.html", fileserver))
|
||||
}
|
||||
r.HandleFunc("/*", serveIndex("webapp", "index.html", fileserver))
|
||||
|
||||
go http.Serve(listener, r)
|
||||
<-ctx.Done()
|
||||
}
|
||||
}
|
||||
+7
-58
@@ -1,68 +1,17 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
context "github.com/SentimensRG/ctx"
|
||||
"github.com/SentimensRG/ctx/sigctx"
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
"github.com/namsral/flag"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
|
||||
"github.com/crusttech/crust/internal/logger"
|
||||
"github.com/crusttech/crust/internal/subscription"
|
||||
messaging "github.com/crusttech/crust/messaging"
|
||||
system "github.com/crusttech/crust/system"
|
||||
"github.com/cortezaproject/corteza-server/messaging"
|
||||
"github.com/cortezaproject/corteza-server/pkg/cli"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Initialize default logger
|
||||
logger.Init(zapcore.DebugLevel)
|
||||
log := logger.Default().Named("messaging")
|
||||
|
||||
// New signal-bond context that we will use and
|
||||
// will get terminated (Done()) on SIGINT or SIGTERM
|
||||
ctx := context.AsContext(sigctx.New())
|
||||
|
||||
// Bind default logger to context
|
||||
ctx = logger.ContextWithValue(ctx, log)
|
||||
|
||||
messaging.Flags("messaging")
|
||||
system.Flags("system")
|
||||
|
||||
subscription.Flags()
|
||||
|
||||
flag.Parse()
|
||||
|
||||
if err := system.Init(ctx); err != nil {
|
||||
log.Fatal("failed to initialize system", zap.Error(err))
|
||||
}
|
||||
if err := messaging.Init(ctx); err != nil {
|
||||
log.Fatal("failed to initialize messaging", zap.Error(err))
|
||||
}
|
||||
|
||||
var command string
|
||||
if len(os.Args) > 1 {
|
||||
command = os.Args[1]
|
||||
}
|
||||
|
||||
switch command {
|
||||
case "help":
|
||||
flag.PrintDefaults()
|
||||
|
||||
case "provision":
|
||||
if err := messaging.Provision(ctx); err != nil {
|
||||
println("Failed to provision messagign: ", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
default:
|
||||
// Checks subscription, will os.Exit(1) if there is an error
|
||||
// Disabled for now, system service is the only one that validates subscription
|
||||
// ctx = subscription.Monitor(ctx)
|
||||
|
||||
if err := messaging.StartRestAPI(ctx); err != nil {
|
||||
log.Fatal("failed to start messaging REST API", zap.Error(err))
|
||||
}
|
||||
m := messaging.InitMessaging()
|
||||
if err := m.Command(cli.Context()).Execute(); err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/monolith"
|
||||
"github.com/cortezaproject/corteza-server/pkg/cli"
|
||||
)
|
||||
|
||||
func main() {
|
||||
c := monolith.InitMonolith()
|
||||
if err := c.Command(cli.Context()).Execute(); err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
"github.com/namsral/flag"
|
||||
)
|
||||
|
||||
func flags(prefix string, mountFlags ...func(...string)) {
|
||||
for _, mount := range mountFlags {
|
||||
mount(prefix)
|
||||
}
|
||||
flag.Parse()
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
context "github.com/SentimensRG/ctx"
|
||||
"github.com/SentimensRG/ctx/sigctx"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
|
||||
"github.com/crusttech/crust/internal/logger"
|
||||
system "github.com/crusttech/crust/system"
|
||||
"github.com/crusttech/crust/system/cli"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
// Initialize default logger
|
||||
logger.Init(zapcore.DebugLevel)
|
||||
log := logger.Default().Named("system-cli")
|
||||
|
||||
// New signal-bond context that we will use and
|
||||
// will get terminated (Done()) on SIGINT or SIGTERM
|
||||
ctx := context.AsContext(sigctx.New())
|
||||
|
||||
// Bind default logger to context
|
||||
ctx = logger.ContextWithValue(ctx, log)
|
||||
|
||||
flags("system", system.Flags)
|
||||
if err := system.Init(ctx); err != nil {
|
||||
log.Fatal("failed to initialize system", zap.Error(err))
|
||||
}
|
||||
|
||||
cli.StartCLI(ctx)
|
||||
}
|
||||
+7
-52
@@ -1,62 +1,17 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
context "github.com/SentimensRG/ctx"
|
||||
"github.com/SentimensRG/ctx/sigctx"
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
"github.com/namsral/flag"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
|
||||
"github.com/crusttech/crust/internal/logger"
|
||||
"github.com/crusttech/crust/internal/subscription"
|
||||
system "github.com/crusttech/crust/system"
|
||||
"github.com/cortezaproject/corteza-server/pkg/cli"
|
||||
"github.com/cortezaproject/corteza-server/system"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
// Initialize default logger
|
||||
logger.Init(zapcore.DebugLevel)
|
||||
log := logger.Default().Named("system")
|
||||
|
||||
// New signal-bond context that we will use and
|
||||
// will get terminated (Done()) on SIGINT or SIGTERM
|
||||
ctx := context.AsContext(sigctx.New())
|
||||
|
||||
// Bind default logger to context
|
||||
ctx = logger.ContextWithValue(ctx, log)
|
||||
|
||||
system.Flags("system")
|
||||
|
||||
subscription.Flags()
|
||||
|
||||
flag.Parse()
|
||||
|
||||
if err := system.Init(ctx); err != nil {
|
||||
log.Fatal("failed to initialize system", zap.Error(err))
|
||||
}
|
||||
|
||||
var command string
|
||||
if len(os.Args) > 1 {
|
||||
command = os.Args[1]
|
||||
}
|
||||
|
||||
switch command {
|
||||
case "help":
|
||||
flag.PrintDefaults()
|
||||
case "provision":
|
||||
if err := system.Provision(ctx); err != nil {
|
||||
println("Failed to provision system: ", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
default:
|
||||
// Checks subscription, will os.Exit(1) if there is an error
|
||||
ctx = subscription.Monitor(ctx)
|
||||
|
||||
if err := system.StartRestAPI(ctx); err != nil {
|
||||
log.Fatal("failed to start system REST API", zap.Error(err))
|
||||
}
|
||||
s := system.InitSystem()
|
||||
if err := s.Command(cli.Context()).Execute(); err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user