Skip to content

🎥 Make videos programmatically with React

move validation structure

Alex Fernandez598c86217e88
diff --git a/packages/goclient-example/main.go b/packages/goclient-example/main.go
index e4a4ac21cf..ad08e549f3 100644
--- a/packages/goclient-example/main.go
+++ b/packages/goclient-example/main.go
@@ -10,6 +10,21 @@ import (
"github.com/remotion-dev/remotion/packages/goclient"
)
+type ValidationError struct {
+ Field string
+ Message string
+}
+
+func msgForTag(fe validator.FieldError) string {
+ switch fe.Tag() {
+ case "required":
+ return "This field is required"
+ case "email":
+ return "Invalid email"
+ }
+ return fe.Error() // default error
+}
+
func main() {
// Load the environment variables from the .env file
@@ -66,13 +81,13 @@ func main() {
if error != nil {
- out := make([]ApiError, len(error.(validator.ValidationErrors)))
+ validationOut := make([]ValidationError, len(error.(validator.ValidationErrors)))
for i, fieldError := range error.(validator.ValidationErrors) {
- out[i] = ApiError{fieldError.Field(), msgForTag(fieldError)}
+ validationOut[i] = ValidationError{fieldError.Field(), msgForTag(fieldError)}
}
- for _, apiError := range out {
+ for _, apiError := range validationOut {
fmt.Printf("%s: %s\n", apiError.Param, apiError.Message)
}
return
@@ -101,18 +116,3 @@ func main() {
fmt.Printf("bucketName: %s\nRenderId: %s\n", bucketName, renderId)
}
-
-type ApiError struct {
- Param string
- Message string
-}
-
-func msgForTag(fe validator.FieldError) string {
- switch fe.Tag() {
- case "required":
- return "This field is required"
- case "email":
- return "Invalid email"
- }
- return fe.Error() // default error
-}