Home >Backend Development >Golang >Dynamic string validation using go&#s text/template package

Dynamic string validation using go&#s text/template package

Susan Sarandon
Susan SarandonOriginal
2024-12-30 06:19:08246browse

Dynamic string validation using go

Imagine you could validate the following string:

id: "d416e1b0-97b2-4a49-8ad5-2e6b2b46eae0"
static-string: "abc"
invalid-string: def
random-number: 150

Using go template syntax like this:

id: "{{isUUID}}"
static-string: "abc"
invalid-string: def
random-number: {{inRange 100 200}}

Well, that would be cool wouldn't it? Unfortunately this isn't supported by go's text/template package.

I've built a library which uses a subset of the template syntax to cover this specific use-case: github.com/sleeyax/templatex-go. Check it out for a more detailed example!


Hi ? thanks for reading! If you enjoyed reading my content, consider following me on Twitter to stay in the loop ❤️.

The above is the detailed content of Dynamic string validation using go&#s text/template package. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn