mirror of
https://gitee.com/johng/gf.git
synced 2024-11-30 03:07:45 +08:00
43 lines
798 B
Go
43 lines
798 B
Go
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
|
//
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
// If a copy of the MIT was not distributed with this file,
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
package builtin
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/gogf/gf/v2/net/gipv6"
|
|
)
|
|
|
|
// RuleIpv6 implements `ipv6` rule:
|
|
// IPv6.
|
|
//
|
|
// Format: ipv6
|
|
type RuleIpv6 struct{}
|
|
|
|
func init() {
|
|
Register(RuleIpv6{})
|
|
}
|
|
|
|
func (r RuleIpv6) Name() string {
|
|
return "ipv6"
|
|
}
|
|
|
|
func (r RuleIpv6) Message() string {
|
|
return "The {field} value `{value}` is not a valid IPv6 address"
|
|
}
|
|
|
|
func (r RuleIpv6) Run(in RunInput) error {
|
|
var (
|
|
ok bool
|
|
value = in.Value.String()
|
|
)
|
|
if ok = gipv6.Validate(value); !ok {
|
|
return errors.New(in.Message)
|
|
}
|
|
return nil
|
|
}
|