github.com/wangyougui/gf/v2@v2.6.5/util/gvalid/internal/builtin/builtin_ipv6.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/wangyougui/gf. 6 7 package builtin 8 9 import ( 10 "errors" 11 12 "github.com/wangyougui/gf/v2/net/gipv6" 13 ) 14 15 // RuleIpv6 implements `ipv6` rule: 16 // IPv6. 17 // 18 // Format: ipv6 19 type RuleIpv6 struct{} 20 21 func init() { 22 Register(RuleIpv6{}) 23 } 24 25 func (r RuleIpv6) Name() string { 26 return "ipv6" 27 } 28 29 func (r RuleIpv6) Message() string { 30 return "The {field} value `{value}` is not a valid IPv6 address" 31 } 32 33 func (r RuleIpv6) Run(in RunInput) error { 34 var ( 35 ok bool 36 value = in.Value.String() 37 ) 38 if ok = gipv6.Validate(value); !ok { 39 return errors.New(in.Message) 40 } 41 return nil 42 }