Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions app/filters/append_suffix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package filters

import (
"context"
"fmt"
)

type AppendSuffix struct{}

func (r *AppendSuffix) Signature() string {
return "append_suffix"
}

func (r *AppendSuffix) Handle(ctx context.Context) any {
return func(val string, suffix ...string) (string, error) {
if len(suffix) == 0 {
return "", fmt.Errorf("append_suffix requires at least one suffix")
}

return val + suffix[0], nil
}
}
37 changes: 37 additions & 0 deletions app/http/controllers/validation_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
contractsvalidation "github.com/goravel/framework/contracts/validation"
"github.com/goravel/framework/support/carbon"
"github.com/goravel/framework/validation"
"github.com/spf13/cast"

"goravel/app/facades"
"goravel/app/http/requests"
Expand Down Expand Up @@ -158,3 +159,39 @@ func (r *ValidationController) Form(ctx http.Context) http.Response {
"name": user.Name,
})
}

func (r *ValidationController) Upload(ctx http.Context) http.Response {
rule := cast.ToString(ctx.Request().Input("rule"))
message := cast.ToString(ctx.Request().Input("message"))
if rule == "" {
return ctx.Response().Json(http.StatusBadRequest, http.Json{
"message": "rule is required",
})
}

options := make([]contractsvalidation.Option, 0)
if message != "" {
options = append(options, validation.Messages(map[string]string{
"f." + rule: message,
}))
}

validator, err := ctx.Request().Validate(map[string]string{
"f": rule,
}, options...)
Comment thread
hwbrzzl marked this conversation as resolved.
if err != nil {
return ctx.Response().Json(http.StatusBadRequest, http.Json{
"message": err.Error(),
})
}

if validator.Fails() {
return ctx.Response().Json(http.StatusBadRequest, http.Json{
"message": validator.Errors().All(),
})
}

return ctx.Response().Success().Json(http.Json{
"ok": true,
})
}
1 change: 1 addition & 0 deletions bootstrap/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func Boot() contractsfoundation.Application {
}).
WithCommands(Commands).
WithJobs(Jobs).
WithFilters(Filters).
WithRules(Rules).
WithMiddleware(func(handler configuration.Middleware) {
handler.Append(
Expand Down
13 changes: 13 additions & 0 deletions bootstrap/filters.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package bootstrap

import (
"github.com/goravel/framework/contracts/validation"

"goravel/app/filters"
)

func Filters() []validation.Filter {
return []validation.Filter{
&filters.AppendSuffix{},
}
}
4 changes: 2 additions & 2 deletions config/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func init() {
"reader": map[string]any{
// Interval: How often metrics are pushed.
// Format: Duration string (e.g., "60s", "1m", "500ms").
"interval": config.Env("OTEL_METRIC_EXPORT_INTERVAL", "1s"),
"interval": config.Env("OTEL_METRIC_EXPORT_INTERVAL", "10s"),

// Timeout: Max time allowed for export before cancelling.
// Format: Duration string (e.g., "30s", "10s").
Expand All @@ -114,7 +114,7 @@ func init() {
"processor": map[string]any{
// Interval: How often logs are flushed.
// Format: Duration string (e.g., "1s", "500ms").
"interval": config.Env("OTEL_LOG_EXPORT_INTERVAL", "1s"),
"interval": config.Env("OTEL_LOG_EXPORT_INTERVAL", "10s"),

// Timeout: Max time allowed for export before cancelling.
// Format: Duration string (e.g., "30s").
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,5 @@ require (
gorm.io/gorm v1.31.1 // indirect
gorm.io/plugin/dbresolver v1.6.2 // indirect
)

replace github.com/goravel/framework v1.17.2 => github.com/goravel/framework v1.17.2-0.20260215045043-365219d1eb4e
1 change: 1 addition & 0 deletions routes/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func Api() {
facades.Route().Post("/validation/json", validationController.Json)
facades.Route().Post("/validation/request", validationController.Request)
facades.Route().Post("/validation/form", validationController.Form)
facades.Route().Post("/validation/upload", validationController.Upload)

// Localization
langController := controllers.NewLangController()
Expand Down
2 changes: 1 addition & 1 deletion tests/feature/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (s *TelemetryTestSuite) SetupSuite() {
resp.AssertSuccessful()

// Wait for telemetry data to be exported
time.Sleep(2 * time.Second)
time.Sleep(11 * time.Second)
}

func (s *TelemetryTestSuite) TearDownSuite() {
Expand Down
491 changes: 491 additions & 0 deletions tests/feature/validation_test.go

Large diffs are not rendered by default.

Loading