You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

gstr提供了丰富的字符串处理。组件内置了90+个常用的字符串处理方法。

使用方式

import "github.com/gogf/gf/text/gstr"

接口文档

https://godoc.org/github.com/gogf/gf/text/gstr



AddSlashes

  • 格式: different:field
  • 说明:参数值不能与field参数的值相同
  • 示例:备用邮箱OtherMailAddr和邮箱地址MailAddr必须不相同
    func ExampleValidator_Different()  {
    	type BizReq struct {
    		Name        	string 	`v:"required"`
    		MailAddr		string 	`v:"required"`
    		OtherMailAddr	string 	`v:"required|different:MailAddr"`
    	}
    	var (
    		ctx = context.Background()
    		req = BizReq{
    			Name:   		"gf",
    			MailAddr:		"gf@goframe.org",
    			OtherMailAddr:	"gf@goframe.org",
    		}
    	)
    	if err := g.Validator().CheckStruct(ctx, req); err != nil {
    		fmt.Println(err)
    	}
    
    	// Output:
    	// The OtherMailAddr value must be different from field MailAddr
    }
  • No labels