-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathErrorMessages.go
95 lines (78 loc) · 3.02 KB
/
ErrorMessages.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package gotten
import (
"errors"
"fmt"
"net/http"
"reflect"
"strings"
)
const (
BaseUrlCannotBeEmpty = "baseUrl cannot be empty"
MustPassPtrToImpl = "must pass the ptr of the service to be implemented"
ServiceMustBeStruct = "service must be struct"
UnrecognizedHTTPMethod = "http method is unrecognized"
ParamTypeMustBePtrOfStruct = "param type must be ptr of struct"
ValueIsNotString = "value is not a string"
ValueIsNotInt = "value is not a int"
DuplicatedPathKey = "duplicated path key"
UnsupportedValueType = "field type is unrecognized"
UnrecognizedPathKey = "path key is unrecognized"
EmptyRequiredVariable = "required variable is empty"
UnsupportedFieldType = "field type is unsupported"
SomePathVarHasNoValue = "some pathValue has no value"
NoUnmarshalerFoundForResponse = "no unmarshaler found for response"
ContentTypeConflict = "content type conflict: "
UnsupportedFuncType = "function type is not supported"
)
func MustPassPtrToImplError(p reflect.Type) error {
return errors.New(MustPassPtrToImpl + ": " + p.String())
}
func ServiceMustBeStructError(p reflect.Type) error {
return errors.New(ServiceMustBeStruct + ": " + p.String())
}
func UnrecognizedHTTPMethodError(method string) error {
return errors.New(UnrecognizedHTTPMethod + ": " + method)
}
func ParamTypeMustBePtrOfStructError(p reflect.Type) error {
return errors.New(ParamTypeMustBePtrOfStruct + ": " + p.String())
}
func ValueIsNotStringError(p reflect.Type) error {
return errors.New(ValueIsNotString + ": " + p.String())
}
func ValueIsNotIntError(p reflect.Type) error {
return errors.New(ValueIsNotInt + ": " + p.String())
}
func DuplicatedPathKeyError(key string) error {
return errors.New(DuplicatedPathKey + ": " + key)
}
func UnsupportedValueTypeError(valueType string) error {
return errors.New(UnsupportedValueType + ": " + valueType)
}
func UnrecognizedPathKeyError(key string) error {
return errors.New(UnrecognizedPathKey + ": " + key)
}
func EmptyRequiredVariableError(name string) error {
return errors.New(EmptyRequiredVariable + ": " + name)
}
func UnsupportedFieldTypeError(fieldType reflect.Type, valueType string) error {
return errors.New(fmt.Sprintf(UnsupportedFieldType+": %s -> %s", fieldType, valueType))
}
func SomePathVarHasNoValueError(list PathKeyList) error {
buf := strings.Builder{}
buf.WriteString(SomePathVarHasNoValue)
buf.WriteString(": ")
for key := range list {
buf.WriteString(" ")
buf.WriteString(key)
}
return errors.New(buf.String())
}
func NoUnmarshalerFoundForResponseError(response *http.Response) error {
return errors.New(fmt.Sprintf(NoUnmarshalerFoundForResponse+"%#v", response))
}
func ContentTypeConflictError(former string, latter string) error {
return errors.New(fmt.Sprintf(ContentTypeConflict+" %s(former), %s(former)", former, latter))
}
func UnsupportedFuncTypeError(p reflect.Type) error {
return errors.New(UnsupportedFuncType + ": " + p.String())
}