<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>String on Ricky</title><link>https://linzeyan.github.io/zh-tw/categories/string/</link><description>Recent content in String on Ricky</description><generator>Hugo -- gohugo.io</generator><language>zh-tw</language><lastBuildDate>Tue, 20 Aug 2024 08:55:00 +0800</lastBuildDate><atom:link href="https://linzeyan.github.io/zh-tw/categories/string/index.xml" rel="self" type="application/rss+xml"/><item><title>Go 文章</title><link>https://linzeyan.github.io/zh-tw/posts/2024/20240820-golang/</link><pubDate>Tue, 20 Aug 2024 08:55:00 +0800</pubDate><guid>https://linzeyan.github.io/zh-tw/posts/2024/20240820-golang/</guid><description>&lt;ul>
&lt;li>&lt;a href="https://juejin.cn/post/6863765115456454664" target="_blank" rel="noopener">學會 gin 參數校驗之 validator 函式庫，看這一篇就夠了&lt;/a>&lt;/li>
&lt;/ul>
&lt;h3 id="字串約束">字串約束&lt;/h3>
&lt;p>excludesall：不包含參數中任意的 UNICODE 字元，例如 excludesall=ab&lt;/p>
&lt;p>excludesrune：不包含參數表示的 rune 字元，excludesrune=asong&lt;/p>
&lt;p>startswith：以參數子字串為前綴，例如 startswith=hi&lt;/p>
&lt;p>endswith：以參數子字串為後綴，例如 endswith=bye。&lt;/p>
&lt;p>contains=：包含參數子字串，例如 contains=email&lt;/p>
&lt;p>containsany：包含參數中任意的 UNICODE 字元，例如 containsany=ab&lt;/p>
&lt;p>containsrune：包含參數表示的 rune 字元，例如 &lt;code>containsrune=asong&lt;/code>&lt;/p>
&lt;p>excludes：不包含參數子字串，例如 excludes=email&lt;/p>
&lt;h3 id="範圍約束">範圍約束&lt;/h3>
&lt;p>範圍約束的欄位型別分為三種：&lt;/p>
&lt;p>對於數值，我們可以約束其值
對於切片、陣列和 map，我們可以約束其長度
對於字串，我們可以約束其長度&lt;/p>
&lt;h4 id="常用-tag-介紹">常用 tag 介紹：&lt;/h4>
&lt;p>ne：不等於參數值，例如 ne=5
gt：大於參數值，例如 gt=5
gte：大於等於參數值，例如 gte=50
lt：小於參數值，例如 lt=50
lte：小於等於參數值，例如 lte=50
oneof：只能是列舉出的值其中之一，這些值必須是數值或字串，以空格分隔；如果字串中有空格，請用單引號包起來，例如 oneof=male female。
eq：等於參數值，注意與 len 不同。對於字串，eq 約束字串本身的值，而 len 約束字串長度。例如 eq=10
len：等於參數值，例如 len=10
max：小於等於參數值，例如 max=10
min：大於等於參數值，例如 min=10&lt;/p>
&lt;h3 id="欄位約束">欄位約束&lt;/h3>
&lt;p>eqfield：定義欄位間相等約束，用於約束同一結構體中的欄位。例如：eqfield=Password
eqcsfield：約束同一結構體中欄位等於另一個欄位（相對），確認密碼時可以使用，例如：eqcsfield=ConfirmPassword
nefield：用來約束兩個欄位是否不同，確認兩種顏色是否一致時可以使用，例如：nefield=Color1
necsfield：約束兩個欄位是否不同（相對）&lt;/p>
&lt;h3 id="常用約束">常用約束&lt;/h3>
&lt;p>unique：指定唯一性約束，不同型別處理不同：&lt;/p></description></item></channel></rss>