Skip to content

Commit

Permalink
feat: change index routes
Browse files Browse the repository at this point in the history
  • Loading branch information
pupilcc committed Jan 10, 2024
1 parent 7b69cff commit 7696322
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
10 changes: 1 addition & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/golang-jwt/jwt/v5"
echojwt "github.com/labstack/echo-jwt/v4"
"github.com/labstack/echo/v4"
"net/http"
"os"
)

Expand All @@ -26,14 +25,7 @@ func main() {
e.Use(jwtMiddleware)

// Routes
e.GET("/", func(c echo.Context) error {
return c.String(http.StatusOK, "Hello, World!")
})
e.GET("/health", func(c echo.Context) error {
return c.JSON(http.StatusOK, map[string]interface{}{
"status": "UP",
})
})
web.IndexRoutes(e)
web.SSLRoutes(e)
web.LoginRoutes(e)

Expand Down
20 changes: 20 additions & 0 deletions web/index.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package web

import (
"github.com/labstack/echo/v4"
"net/http"
)

func IndexRoutes(e *echo.Echo) {
e.GET("/", index)
e.HEAD("/", indexHead)
}

func index(c echo.Context) error {
return c.String(http.StatusOK, "Hello, World!")
}

func indexHead(c echo.Context) error {
c.Response().Header().Set(echo.HeaderContentType, echo.MIMETextHTMLCharsetUTF8)
return c.NoContent(http.StatusOK)
}
16 changes: 8 additions & 8 deletions web/ssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ func generate(c echo.Context) error {
}

certs := service.GetCerts()
if certs != nil {
for _, cert := range certs {
if cert.Name == certCommand.Domain {
err := exception.CertificateExistsErr(certCommand.Domain)
_ = c.JSON(http.StatusBadRequest, response.Message(err.Error()))
return nil
}
}
existingCerts := make(map[string]struct{})
for _, cert := range certs {
existingCerts[cert.Name] = struct{}{}
}
if _, exists := existingCerts[certCommand.Domain]; exists {
err := exception.CertificateExistsErr(certCommand.Domain)
_ = c.JSON(http.StatusBadRequest, response.Message(err.Error()))
return nil
}

id := util.GenerateID()
Expand Down

0 comments on commit 7696322

Please sign in to comment.