52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
"net"
|
|
|
|
v1 "git.badhouseplants.net/softplayer/softplayer-backend/api/v1"
|
|
"git.badhouseplants.net/softplayer/softplayer-go-proto/pkg/accounts"
|
|
"git.badhouseplants.net/softplayer/softplayer-go-proto/pkg/environments"
|
|
"github.com/alecthomas/kong"
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/reflection"
|
|
ctrl "sigs.k8s.io/controller-runtime"
|
|
)
|
|
|
|
var CLI struct {
|
|
Serve struct {
|
|
} `cmd:"" help:"Remove files."`
|
|
|
|
Ls struct {
|
|
Paths []string `arg:"" optional:"" name:"path" help:"Paths to list." type:"path"`
|
|
} `cmd:"" help:"List paths."`
|
|
}
|
|
|
|
func main() {
|
|
ctx := kong.Parse(&CLI)
|
|
switch ctx.Command() {
|
|
case "serve":
|
|
server()
|
|
case "ls":
|
|
default:
|
|
panic(ctx.Command())
|
|
}
|
|
}
|
|
|
|
func server() {
|
|
controller, _ := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{})
|
|
go controller.Start(context.Background())
|
|
lis, err := net.Listen("tcp", fmt.Sprintf("localhost:%d", 8080))
|
|
if err != nil {
|
|
log.Fatalf("failed to listen: %v", err)
|
|
}
|
|
var opts []grpc.ServerOption
|
|
grpcServer := grpc.NewServer(opts...)
|
|
reflection.Register(grpcServer)
|
|
environments.RegisterEnvironmentsServer(grpcServer, v1.NewapiGrpcImpl())
|
|
accounts.RegisterAccountsServer(grpcServer, v1.NewAccountRPCImpl(controller))
|
|
grpcServer.Serve(lis)
|
|
}
|