diff options
| author | Kyren223 <Kyren223@proton.me> | 2024-11-27 17:34:28 +0200 |
|---|---|---|
| committer | Kyren223 <Kyren223@proton.me> | 2024-11-27 17:34:28 +0200 |
| commit | be22bb89db0b952ea0545e7c65b46e92ebb205d2 (patch) | |
| tree | da9b2123d826a2ab61ab8c4e53ee102c5f966f32 /internal/server/api/helpers.go | |
| parent | 6a34d7be01256df472015564a655d8253acd8724 (diff) | |
Added create network to server api
Diffstat (limited to 'internal/server/api/helpers.go')
| -rw-r--r-- | internal/server/api/helpers.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/internal/server/api/helpers.go b/internal/server/api/helpers.go new file mode 100644 index 0000000..967f308 --- /dev/null +++ b/internal/server/api/helpers.go @@ -0,0 +1,23 @@ +package api + +import "strings" + +const hex = "0123456789abcdefABCDEF" + +func isValidHexColor(color string) (bool, string) { + if len(color) != 7 { + return false, "color must be hex with length of 7" + } + + if color[0] != '#' { + return false, "color must start with '#'" + } + + for _, c := range color { + if !strings.ContainsRune(hex, c) { + return false, "color must start with '#' and contain exactly 6 digits 0-9, a-f, A-F" + } + } + + return true, "" +} |
