From 2932ec74ccad7e6d2f32a1c1b8035f4171d3d217 Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Thu, 20 Jun 2019 21:24:04 -0700 Subject: [PATCH] renamed "StructFieldWrongTypeComplainer" to "StructFieldWrongType" --- bad_request_complainer.go | 2 +- pattern_load.go | 2 +- struct_field_wrong_type_complainer.go | 32 +++++++++++---------------- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/bad_request_complainer.go b/bad_request_complainer.go index b5dda7b..5dc41bd 100644 --- a/bad_request_complainer.go +++ b/bad_request_complainer.go @@ -85,7 +85,7 @@ package pathmatch // // Note that one can get more specific than just a BadRequestComplainer. For example: // NotEnoughArgumentsComplainer, PatternSyntaxErrorComplainer, UnsupportedArgumentType, -// and StructFieldWrongTypeComplainer. +// and StructFieldWrongType. // // To be able to detect those more specific error types, put them BEFORE the "case pathmatch.BadRequestComplainer:" // in the type switch. For example: diff --git a/pattern_load.go b/pattern_load.go index c9dca8f..162fb58 100644 --- a/pattern_load.go +++ b/pattern_load.go @@ -72,7 +72,7 @@ func (pattern *internalPattern) MatchAndLoad(path string, strct interface{}) (bo needle = " is not assignable to type " if strings.Contains(s, needle) { - err = newStructFieldWrongTypeComplainer(matchName) + err = newStructFieldWrongType(matchName) return } } diff --git a/struct_field_wrong_type_complainer.go b/struct_field_wrong_type_complainer.go index 0381b23..514a03a 100644 --- a/struct_field_wrong_type_complainer.go +++ b/struct_field_wrong_type_complainer.go @@ -1,40 +1,36 @@ package pathmatch - import ( "bytes" "fmt" ) - const structFieldWrongTypeMessagePrefix = "Bad Request: Wrong type for match " - -type StructFieldWrongTypeComplainer interface { +type StructFieldWrongType interface { BadRequestComplainer MatchName() string } -// internalStructFieldWrongTypeComplainer is the only underlying implementation that fits the -// StructFieldWrongTypeComplainer interface, in this library. -type internalStructFieldWrongTypeComplainer struct { +// internalStructFieldWrongType is the only underlying implementation that fits the +// StructFieldWrongType interface, in this library. +type internalStructFieldWrongType struct { matchName string } -// newStructFieldWrongTypeComplainer creates a new internalStructFieldWrongTypeComplainer (struct) and -// returns it as a StructFieldWrongTypeComplainer (interface). -func newStructFieldWrongTypeComplainer(matchName string) StructFieldWrongTypeComplainer { - err := internalStructFieldWrongTypeComplainer{ +// newStructFieldWrongType creates a new internalStructFieldWrongType (struct) and +// returns it as a StructFieldWrongType (interface). +func newStructFieldWrongType(matchName string) StructFieldWrongType { + err := internalStructFieldWrongType{ matchName:matchName, } return &err } - -// Error method is necessary to satisfy the 'error' interface (and the StructFieldWrongTypeComplainer +// Error method is necessary to satisfy the 'error' interface (and the StructFieldWrongType // interface). -func (err *internalStructFieldWrongTypeComplainer) Error() string { +func (err *internalStructFieldWrongType) Error() string { var buffer bytes.Buffer buffer.WriteString(structFieldWrongTypeMessagePrefix) @@ -43,15 +39,13 @@ func (err *internalStructFieldWrongTypeComplainer) Error() string { return buffer.String() } - // BadRequestComplainer method is necessary to satisfy the 'BadRequestComplainer' interface. // It exists to make this error type detectable in a Go type-switch. -func (err *internalStructFieldWrongTypeComplainer) BadRequestComplainer() { +func (err *internalStructFieldWrongType) BadRequestComplainer() { // Nothing here. } - -// DependencyName method is necessary to satisfy the 'StructFieldWrongTypeComplainer' interface. -func (err *internalStructFieldWrongTypeComplainer) MatchName() string { +// DependencyName method is necessary to satisfy the 'StructFieldWrongType' interface. +func (err *internalStructFieldWrongType) MatchName() string { return err.matchName }