Skip to content

Commit

Permalink
Add route printing functionality to main.go
Browse files Browse the repository at this point in the history
  • Loading branch information
funnyzak committed Feb 16, 2024
1 parent b63018c commit 666c358
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"context"
"fmt"
"go-gin/cmd/srv/controller"
"go-gin/pkg/mygin"
"go-gin/pkg/utils"
"go-gin/service/singleton"

"github.com/gin-gonic/gin"
"github.com/ory/graceful"
flag "github.com/spf13/pflag"
)
Expand Down Expand Up @@ -62,6 +64,10 @@ func main() {
fmt.Printf(" - %-7s: %s\n", "Network", utils.Colorize(utils.ColorGreen, fmt.Sprintf("http://%s:%d", ip, port)))
}
}

fmt.Println()
fmt.Println("Server available routes:")
mygin.PrintRoute(srv.Handler.(*gin.Engine))
fmt.Println()
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/mygin/gin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package mygin

import (
"fmt"
"go-gin/pkg/utils"
"net/http"
"strings"

Expand Down Expand Up @@ -64,3 +65,10 @@ func BindForm(c *gin.Context, isForm bool, form interface{}) error {
return c.ShouldBindJSON(form)
}
}

func PrintRoute(r *gin.Engine) {
routes := r.Routes()
for _, route := range routes {
fmt.Printf(" - Route Path: %s, Method: %s\n", utils.Colorize(utils.ColorGreen, route.Path), utils.Colorize(utils.ColorGreen, route.Method))
}
}

0 comments on commit 666c358

Please sign in to comment.