diff --git a/pkg/helpers.go b/pkg/helpers.go index f9193bc..553f222 100644 --- a/pkg/helpers.go +++ b/pkg/helpers.go @@ -12,6 +12,7 @@ You may get a copy of the License at import ( "fmt" "github.com/common-nighthawk/go-figure" + "github.com/jedib0t/go-pretty/v6/table" "github.com/jkaninda/goma-gateway/util" ) @@ -22,3 +23,11 @@ func Intro() { fmt.Println("Copyright (c) 2024 Jonas Kaninda") fmt.Println("Starting Goma Gateway server...") } +func printRoute(routes []Route) { + t := table.NewWriter() + t.AppendHeader(table.Row{"Name", "Route", "Rewrite", "Destination"}) + for _, route := range routes { + t.AppendRow(table.Row{route.Name, route.Path, route.Rewrite, route.Destination}) + } + fmt.Println(t.Render()) +} diff --git a/pkg/proxy.go b/pkg/proxy.go index 65535a1..235b7c0 100644 --- a/pkg/proxy.go +++ b/pkg/proxy.go @@ -100,14 +100,3 @@ func (proxyRoute ProxyRoute) ProxyHandler() http.HandlerFunc { proxy.ServeHTTP(w, r) } } - -func isAllowed(cors []string, r *http.Request) bool { - for _, origin := range cors { - if origin == r.Header.Get("Origin") { - return true - } - continue - } - return false - -} diff --git a/pkg/route.go b/pkg/route.go index 8db8867..bc7cca1 100644 --- a/pkg/route.go +++ b/pkg/route.go @@ -16,9 +16,7 @@ See the License for the specific language governing permissions and limitations under the License. */ import ( - "fmt" "github.com/gorilla/mux" - "github.com/jedib0t/go-pretty/v6/table" "github.com/jkaninda/goma-gateway/internal/logger" "github.com/jkaninda/goma-gateway/pkg/middleware" "github.com/jkaninda/goma-gateway/util" @@ -134,12 +132,3 @@ func (gatewayServer GatewayServer) Initialize() *mux.Router { return r } - -func printRoute(routes []Route) { - t := table.NewWriter() - t.AppendHeader(table.Row{"Name", "Route", "Rewrite", "Destination"}) - for _, route := range routes { - t.AppendRow(table.Row{route.Name, route.Path, route.Rewrite, route.Destination}) - } - fmt.Println(t.Render()) -} diff --git a/pkg/server.go b/pkg/server.go index 8850be6..9dfbcdc 100644 --- a/pkg/server.go +++ b/pkg/server.go @@ -66,45 +66,3 @@ func (gatewayServer GatewayServer) Start(ctx context.Context) error { return nil } -func waitForReady( - ctx context.Context, - timeout time.Duration, - endpoint string, -) error { - client := http.Client{} - startTime := time.Now() - for { - req, err := http.NewRequestWithContext( - ctx, - http.MethodGet, - endpoint, - nil, - ) - if err != nil { - return fmt.Errorf("failed to create request: %w", err) - } - - resp, err := client.Do(req) - if err != nil { - fmt.Printf("Error making request: %s\n", err.Error()) - continue - } - if resp.StatusCode == http.StatusOK { - fmt.Println("Endpoint is ready!") - resp.Body.Close() - return nil - } - resp.Body.Close() - - select { - case <-ctx.Done(): - return ctx.Err() - default: - if time.Since(startTime) >= timeout { - return fmt.Errorf("timeout reached while waiting for endpoint") - } - // wait a little while between checks - time.Sleep(250 * time.Millisecond) - } - } -}