refactor: clean up code, remove unused methods
This commit is contained in:
@@ -12,6 +12,7 @@ You may get a copy of the License at
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/common-nighthawk/go-figure"
|
"github.com/common-nighthawk/go-figure"
|
||||||
|
"github.com/jedib0t/go-pretty/v6/table"
|
||||||
"github.com/jkaninda/goma-gateway/util"
|
"github.com/jkaninda/goma-gateway/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -22,3 +23,11 @@ func Intro() {
|
|||||||
fmt.Println("Copyright (c) 2024 Jonas Kaninda")
|
fmt.Println("Copyright (c) 2024 Jonas Kaninda")
|
||||||
fmt.Println("Starting Goma Gateway server...")
|
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())
|
||||||
|
}
|
||||||
|
|||||||
11
pkg/proxy.go
11
pkg/proxy.go
@@ -100,14 +100,3 @@ func (proxyRoute ProxyRoute) ProxyHandler() http.HandlerFunc {
|
|||||||
proxy.ServeHTTP(w, r)
|
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
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
11
pkg/route.go
11
pkg/route.go
@@ -16,9 +16,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/jedib0t/go-pretty/v6/table"
|
|
||||||
"github.com/jkaninda/goma-gateway/internal/logger"
|
"github.com/jkaninda/goma-gateway/internal/logger"
|
||||||
"github.com/jkaninda/goma-gateway/pkg/middleware"
|
"github.com/jkaninda/goma-gateway/pkg/middleware"
|
||||||
"github.com/jkaninda/goma-gateway/util"
|
"github.com/jkaninda/goma-gateway/util"
|
||||||
@@ -134,12 +132,3 @@ func (gatewayServer GatewayServer) Initialize() *mux.Router {
|
|||||||
return r
|
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())
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -66,45 +66,3 @@ func (gatewayServer GatewayServer) Start(ctx context.Context) error {
|
|||||||
return nil
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user