diff --git a/main.go b/main.go index 5c9133b..12afb4a 100644 --- a/main.go +++ b/main.go @@ -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" ) @@ -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) diff --git a/web/index.go b/web/index.go new file mode 100644 index 0000000..8e3dacd --- /dev/null +++ b/web/index.go @@ -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) +} diff --git a/web/ssl.go b/web/ssl.go index c14232a..76e28ce 100644 --- a/web/ssl.go +++ b/web/ssl.go @@ -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()