-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
287 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,3 +111,24 @@ func Test_Object(t *testing.T) { | |
}) | ||
}) | ||
} | ||
|
||
func ExampleObject() { | ||
schema := owl.Object().Field( | ||
"email", owl.String().Email().Required(), | ||
).Field( | ||
"password", owl.String().Min(5).Max(20).Required(), | ||
) | ||
|
||
if err := schema.Validate(map[string]any{ | ||
"email": "[email protected]", | ||
"password": "mytestpassword", | ||
}); err != nil { // nil | ||
panic(err) | ||
} | ||
|
||
if err := schema.Validate(map[string]any{ | ||
"email": "[email protected]", | ||
}); err != nil { // error | ||
panic(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,3 +152,87 @@ func Test_String(t *testing.T) { | |
}) | ||
}) | ||
} | ||
|
||
func ExampleString() { | ||
schema := owl.String() | ||
|
||
if err := schema.Validate("test"); err != nil { // nil | ||
panic(err) | ||
} | ||
|
||
if err := schema.Validate(true); err != nil { // error | ||
panic(err) | ||
} | ||
} | ||
|
||
func ExampleStringSchema_Min() { | ||
schema := owl.String().Min(5) | ||
|
||
if err := schema.Validate("tester"); err != nil { // nil | ||
panic(err) | ||
} | ||
|
||
if err := schema.Validate("test"); err != nil { // error | ||
panic(err) | ||
} | ||
} | ||
|
||
func ExampleStringSchema_Max() { | ||
schema := owl.String().Max(5) | ||
|
||
if err := schema.Validate("test"); err != nil { // nil | ||
panic(err) | ||
} | ||
|
||
if err := schema.Validate("tester"); err != nil { // error | ||
panic(err) | ||
} | ||
} | ||
|
||
func ExampleStringSchema_Regex() { | ||
schema := owl.String().Regex(regexp.MustCompile("^[0-9a-zA-Z_-]+$")) | ||
|
||
if err := schema.Validate("test"); err != nil { // nil | ||
panic(err) | ||
} | ||
|
||
if err := schema.Validate("hello world"); err != nil { // error | ||
panic(err) | ||
} | ||
} | ||
|
||
func ExampleStringSchema_Email() { | ||
schema := owl.String().Email() | ||
|
||
if err := schema.Validate("[email protected]"); err != nil { // nil | ||
panic(err) | ||
} | ||
|
||
if err := schema.Validate("test"); err != nil { // error | ||
panic(err) | ||
} | ||
} | ||
|
||
func ExampleStringSchema_UUID() { | ||
schema := owl.String().UUID() | ||
|
||
if err := schema.Validate("afefc1ab-b8f2-4803-8e9a-60515854141a"); err != nil { // nil | ||
panic(err) | ||
} | ||
|
||
if err := schema.Validate("test"); err != nil { // error | ||
panic(err) | ||
} | ||
} | ||
|
||
func ExampleStringSchema_URL() { | ||
schema := owl.String().URL() | ||
|
||
if err := schema.Validate("https://www.google.com"); err != nil { // nil | ||
panic(err) | ||
} | ||
|
||
if err := schema.Validate("test"); err != nil { // error | ||
panic(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters