package api import ( "context" "crypto/rand" "crypto/rsa" "crypto/x509" "encoding/pem" "next-terminal/server/repository" "next-terminal/server/service" "github.com/labstack/echo/v4" ) type PropertyApi struct{} func (api PropertyApi) PropertyGetEndpoint(c echo.Context) error { properties := repository.PropertyRepository.FindAllMap(context.TODO()) return Success(c, properties) } func (api PropertyApi) PropertyUpdateEndpoint(c echo.Context) error { var item map[string]interface{} if err := c.Bind(&item); err != nil { return err } if err := service.PropertyService.Update(item); err != nil { return err } return Success(c, nil) } func (api PropertyApi) GenRSAPrivateKeyEndpoint(c echo.Context) error { key, err := rsa.GenerateKey(rand.Reader, 2048) if err != nil { return err } privateKeyPem := pem.EncodeToMemory(&pem.Block{ Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(key), }) return Success(c, map[string]string{"key": string(privateKeyPem)}) } func (api PropertyApi) SendMailEndpoint(c echo.Context) error { var req map[string]interface{} if err := c.Bind(&req); err != nil { return err } if err := service.MailService.SendTestMail(req); err != nil { return err } return Success(c, nil) } func (api PropertyApi) ClientIPsEndpoint(c echo.Context) error { return Success(c, map[string]string{ "direct": c.RealIP(), "x-real-ip": c.Request().Header.Get("X-Real-IP"), "x-forwarded-for": c.Request().Header.Get("X-Forwarded-For"), }) }