1
0
mirror of https://github.com/chai2010/advanced-go-programming-book.git synced 2025-05-25 13:32:22 +00:00
2018-07-14 21:43:54 +08:00

55 lines
1.5 KiB
Go
Executable File

// Code generated by protoc-gen-gogo.
// source: examples/nested.proto
// DO NOT EDIT!
/*
Package validator_examples is a generated protocol buffer package.
It is generated from these files:
examples/nested.proto
It has these top-level messages:
InnerMessage
OuterMessage
*/
package validator_examples
import regexp "regexp"
import fmt "fmt"
import github_com_mwitkow_go_proto_validators "github.com/mwitkow/go-proto-validators"
import proto "github.com/golang/protobuf/proto"
import math "math"
import _ "github.com/mwitkow/go-proto-validators"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
func (this *InnerMessage) Validate() error {
if !(this.SomeInteger > 0) {
return fmt.Errorf("validation error: InnerMessage.SomeInteger must be greater than '0'")
}
if !(this.SomeInteger < 100) {
return fmt.Errorf("validation error: InnerMessage.SomeInteger must be less than '100'")
}
return nil
}
var _regex_OuterMessage_ImportantString = regexp.MustCompile("^[a-z]{2,5}$")
func (this *OuterMessage) Validate() error {
if !_regex_OuterMessage_ImportantString.MatchString(this.ImportantString) {
return fmt.Errorf("validation error: OuterMessage.ImportantString must conform to regex " + "^[a-z]{2,5}$")
}
if nil == this.Inner {
return fmt.Errorf("validation error: OuterMessage.Inner message must exist")
}
if this.Inner != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Inner); err != nil {
return err
}
}
return nil
}