initial commit

This commit is contained in:
2025-09-19 14:59:07 -04:00
commit 5bb9052fa4
15 changed files with 937 additions and 0 deletions

39
cmd/link.go Normal file
View File

@@ -0,0 +1,39 @@
package cmd
import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"reichard.io/conduit/client"
"reichard.io/conduit/config"
)
var linkCmd = &cobra.Command{
Use: "link <name> <host:port>",
Short: "Create a conduit tunnel",
Run: func(cmd *cobra.Command, args []string) {
// Get Client Config
cfg, err := config.GetClientConfig(cmd.Flags())
if err != nil {
log.Fatal("failed to get client config:", err)
}
// Create Tunnel
tunnel, err := client.NewTunnel(cfg)
if err != nil {
log.Fatal("failed to create tunnel:", err)
}
// Start Tunnel
log.Infof("creating TCP tunnel: %s -> %s", cfg.TunnelName, cfg.TunnelTarget)
if err := tunnel.Start(); err != nil {
log.Fatal("failed to start tunnel:", err)
}
},
}
func init() {
configDefs := config.GetConfigDefs[config.ClientConfig]()
for _, d := range configDefs {
linkCmd.Flags().String(d.Key, d.Default, d.Description)
}
}

26
cmd/root.go Normal file
View File

@@ -0,0 +1,26 @@
package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
)
var rootCmd = &cobra.Command{
Use: "conduit",
Short: "A tunneling service similar to ngrok",
Long: `Conduit allows you to expose local services through secure tunnels`,
}
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
func init() {
rootCmd.AddCommand(serveCmd)
rootCmd.AddCommand(linkCmd)
}

40
cmd/serve.go Normal file
View File

@@ -0,0 +1,40 @@
package cmd
import (
"reichard.io/conduit/config"
"reichard.io/conduit/server"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
var serveCmd = &cobra.Command{
Use: "serve",
Short: "Start the conduit server",
Long: `Start the conduit server to handle incoming tunnel requests`,
Run: func(cmd *cobra.Command, args []string) {
// Get Server Config
cfg, err := config.GetServerConfig(cmd.Flags())
if err != nil {
log.Fatal("failed to get server config:", err)
}
// Create Server
srv, err := server.NewServer(cfg)
if err != nil {
log.Fatal("failed to create server:", err)
}
// Start Server
if err := srv.Start(); err != nil {
log.Fatal("failed to start server:", err)
}
},
}
func init() {
configDefs := config.GetConfigDefs[config.ServerConfig]()
for _, d := range configDefs {
serveCmd.Flags().String(d.Key, d.Default, d.Description)
}
}