diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
new file mode 100644
index 0000000..a322702
--- /dev/null
+++ b/.github/workflows/tests.yml
@@ -0,0 +1,23 @@
+name: Test build
+
+on:
+ pull_request:
+ branches:
+ - main
+
+jobs:
+ main:
+ name: Build and run
+ runs-on: ubuntu-20.04
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v3
+
+ - name: Run tests
+ run: |
+ go test
+
+ - name: Check if binary builds
+ run: |
+ go build .
+
diff --git a/LICENSE b/LICENSE
index ebd4008..3a6dc56 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,24 +1,21 @@
-BSD 2-Clause License
+MIT License
-Copyright (c) 2024, Go Phings
+Copyright (c) 2023, 2024 Mikolaj Gasior
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
-1. Redistributions of source code must retain the above copyright notice, this
- list of conditions and the following disclaimer.
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
-2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
index aa7f156..0842c7e 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,38 @@
# struct-validator
-Verify the values of struct fields using tags
+
+[](https://pkg.go.dev/github.com/go-phings/struct-validator) [](https://goreportcard.com/report/github.com/go-phings/struct-validator) 
+
+Verify the values of struct fields using tags
+
+### Example code
+
+```
+type Test1 struct {
+ FirstName string `validation:"req lenmin:5 lenmax:25"`
+ LastName string `validation:"req lenmin:2 lenmax:50"`
+ Age int `validation:"req valmin:18 valmax:150"`
+ Price int `validation:"req valmin:0 valmax:9999"`
+ PostCode string `validation:"req" validation_regexp:"^[0-9][0-9]-[0-9][0-9][0-9]$"`
+ Email string `validation:"req email"`
+ BelowZero int `validation:"valmin:-6 valmax:-2"`
+ DiscountPrice int `validation:"valmin:0 valmax:8000"`
+ Country string `validation_regexp:"^[A-Z][A-Z]$"`
+ County string `validation:"lenmax:40"`
+}
+
+s := &Test1{
+ FirstName: "Name that is way too long and certainly not valid",
+ ...
+}
+
+o := structvalidator.&ValidationOptions{
+ RestrictFields: map[string]bool{
+ "FirstName": true,
+ "LastName": true,
+ ...
+ },
+ ...
+}
+
+isValid, fieldsWithInvalidValue := structvalidator.Validate(s, &o)
+```
diff --git a/go.mod b/go.mod
new file mode 100644
index 0000000..83895a8
--- /dev/null
+++ b/go.mod
@@ -0,0 +1,3 @@
+module github.com/go-phings/struct-validator
+
+go 1.23.4
diff --git a/html_input_gen.go b/html_input_gen.go
new file mode 100644
index 0000000..bf04c31
--- /dev/null
+++ b/html_input_gen.go
@@ -0,0 +1,212 @@
+package structvalidator
+
+import (
+ "fmt"
+ "html"
+ "reflect"
+ "strconv"
+ "strings"
+)
+
+const TypeText = 1
+const TypeTextarea = 2
+const TypePassword = 3
+const TypeEmail = 4
+
+// Optional configuration for validation:
+// * RestrictFields defines what struct fields should be generated
+// * ExcludeFields defines fields that should be skipped (also from RestrictFields)
+// * OverwriteFieldTags can be used to overwrite tags for specific fields
+// * OverwriteTagName sets tag used to define validation (default is "validation")
+// * ValidateWhenSuffix will validate certain fields based on their name, eg. "PrimaryEmail" field will need to be a valid email
+// * OverwriteFieldValues is to use overwrite values for fields, so these values are validated not the ones in struct
+// * IDPrefix - if added, an element will contain an 'id' attribute in form of prefix + field name
+// * NamePrefix - use this to put a prefix in the 'name' attribute
+// * OverwriteValues - fill inputs with the specified values
+// * FieldValues - when true then fill inputs with struct instance values
+type HTMLOptions struct {
+ RestrictFields map[string]bool
+ ExcludeFields map[string]bool
+ OverwriteFieldTags map[string]map[string]string
+ OverwriteTagName string
+ ValidateWhenSuffix bool
+ IDPrefix string
+ NamePrefix string
+ OverwriteValues map[string]string
+ FieldValues bool
+}
+
+// GenerateHTMLInput takes a struct and generates HTML inputs for each of the fields, eg. or