Skip to content

Commit

Permalink
nope. no polymorphism in golang
Browse files Browse the repository at this point in the history
  • Loading branch information
mvanholsteijn committed Dec 9, 2021
1 parent ec067be commit 87349ae
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 22 deletions.
13 changes: 4 additions & 9 deletions cmd/gkeclient.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"fmt"
"log"

"github.com/binxio/simple-iap-proxy/flags"
Expand All @@ -17,7 +16,6 @@ func newGKEClientCmd() *cobra.Command {
Short: "starts a client side proxy, forwarding requests to the GKE cluster via the IAP",
Long: `The client will start a real HTTP/S proxy and forward any requests for,
ip address of GKE cluster master endpoints, to the IAP proxy.`,
RunE: runProxy,
},
},
}
Expand All @@ -33,13 +31,10 @@ ip address of GKE cluster master endpoints, to the IAP proxy.`,
c.MarkFlagRequired("service-account")
c.MarkFlagRequired("target-url")
c.Flags().SortFlags = false
return &c.Command
}

func runProxy(c *cobra.Command, _ []string) error {
p, ok := interface{}(c).(gkeclient.Proxy)
if !ok {
return fmt.Errorf("command is not a proxy command")
c.RunE = func(cmd *cobra.Command, args []string) error {
return c.Run()
}
return p.Run()

return &c.Command
}
19 changes: 6 additions & 13 deletions cmd/gkeserver.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package cmd

import (
"fmt"

"github.com/binxio/simple-iap-proxy/flags"
"github.com/binxio/simple-iap-proxy/gkeserver"
"github.com/spf13/cobra"
)

func newGKEServerCmd() *cobra.Command {
gkeServerCmd := gkeserver.ReverseProxy{
c := gkeserver.ReverseProxy{
RootCommand: flags.RootCommand{
Command: cobra.Command{
Use: "gke-server",
Expand All @@ -19,18 +17,13 @@ reads the Host header of the http requests and if
it matches the ip address of GKE cluster master endpoint,
forwards the request to it.
`,
RunE: runReverseProxy,
},
},
}

return &gkeServerCmd.Command
}

func runReverseProxy(c *cobra.Command, _ []string) error {
s, ok := interface{}(c).(gkeserver.ReverseProxy)
if !ok {
return fmt.Errorf("command is not a reverse proxy command")
c.AddPersistentFlags()
c.RunE = func(cmd *cobra.Command, args []string) error {
return c.Run()
}
return s.Run()

return &c.Command
}

0 comments on commit 87349ae

Please sign in to comment.