mirror of
https://github.com/yusing/godoxy.git
synced 2026-01-16 08:26:49 +01:00
- Introduced a new method `GetCertInfos` to fetch details of all available certificates. - Updated the `Info` handler to return an array of `CertInfo` instead of a single certificate. - Improved error handling for cases with no available certificates. - Refactored related error messages for clarity.
42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
package certapi
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/yusing/godoxy/internal/autocert"
|
|
apitypes "github.com/yusing/goutils/apitypes"
|
|
)
|
|
|
|
// @x-id "info"
|
|
// @BasePath /api/v1
|
|
// @Summary Get cert info
|
|
// @Description Get cert info
|
|
// @Tags cert
|
|
// @Produce json
|
|
// @Success 200 {array} autocert.CertInfo
|
|
// @Failure 403 {object} apitypes.ErrorResponse "Unauthorized"
|
|
// @Failure 404 {object} apitypes.ErrorResponse "No certificates found or autocert is not enabled"
|
|
// @Failure 500 {object} apitypes.ErrorResponse "Internal server error"
|
|
// @Router /cert/info [get]
|
|
func Info(c *gin.Context) {
|
|
provider := autocert.ActiveProvider.Load()
|
|
if provider == nil {
|
|
c.JSON(http.StatusNotFound, apitypes.Error("autocert is not enabled"))
|
|
return
|
|
}
|
|
|
|
certInfos, err := provider.GetCertInfos()
|
|
if err != nil {
|
|
if errors.Is(err, autocert.ErrNoCertificates) {
|
|
c.JSON(http.StatusNotFound, apitypes.Error("no certificate found"))
|
|
return
|
|
}
|
|
c.Error(apitypes.InternalServerError(err, "failed to get cert info"))
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, certInfos)
|
|
}
|