Files
giredore/domains/server/v1/configapi.go
T

33 lines
1005 B
Go
Raw Normal View History

2019-10-05 21:53:22 +05:00
package serverv1
import (
"net/http"
"github.com/labstack/echo"
"go.dev.pztrn.name/giredore/internal/configuration"
"go.dev.pztrn.name/giredore/internal/structs"
2019-10-05 21:53:22 +05:00
)
// This function responsible for getting runtime configuration.
func configurationGET(ec echo.Context) error {
// nolint:wrapcheck
2020-04-27 03:51:24 +05:00
return ec.JSON(http.StatusOK, configuration.Cfg)
2019-10-05 21:53:22 +05:00
}
2019-10-07 18:21:26 +05:00
func configurationAllowedIPsSET(ectx echo.Context) error {
// nolint:exhaustruct
2019-10-07 18:21:26 +05:00
req := &structs.AllowedIPsSetRequest{}
if err := ectx.Bind(req); err != nil {
2019-10-07 18:21:26 +05:00
log.Error().Err(err).Msg("Failed to parse allowed IPs set request")
// nolint:exhaustruct,wrapcheck
return ectx.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: []structs.Error{structs.ErrParsingAllowedIPsSetRequest}})
2019-10-07 18:21:26 +05:00
}
log.Debug().Msgf("Got set allowed IPs request: %+v", req)
configuration.Cfg.SetAllowedIPs(req.AllowedIPs)
// nolint:exhaustruct,wrapcheck
return ectx.JSON(http.StatusOK, &structs.Reply{Status: structs.StatusSuccess})
2019-10-07 18:21:26 +05:00
}