Skip to content

Commit 154f5df

Browse files
committed
Move decoder code into new internal package
1 parent 89ebd22 commit 154f5df

File tree

11 files changed

+260
-207
lines changed

11 files changed

+260
-207
lines changed

errors.go

Lines changed: 9 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,13 @@
11
package maxminddb
22

3-
import (
4-
"fmt"
5-
"reflect"
6-
)
7-
8-
// InvalidDatabaseError is returned when the database contains invalid data
9-
// and cannot be parsed.
10-
type InvalidDatabaseError struct {
11-
message string
12-
}
13-
14-
func newOffsetError() InvalidDatabaseError {
15-
return InvalidDatabaseError{"unexpected end of database"}
16-
}
17-
18-
func newInvalidDatabaseError(format string, args ...any) InvalidDatabaseError {
19-
return InvalidDatabaseError{fmt.Sprintf(format, args...)}
20-
}
3+
import "github.com/oschwald/maxminddb-golang/v2/internal/mmdberrors"
214

22-
func (e InvalidDatabaseError) Error() string {
23-
return e.message
24-
}
5+
type (
6+
// InvalidDatabaseError is returned when the database contains invalid data
7+
// and cannot be parsed.
8+
InvalidDatabaseError = mmdberrors.InvalidDatabaseError
259

26-
// UnmarshalTypeError is returned when the value in the database cannot be
27-
// assigned to the specified data type.
28-
type UnmarshalTypeError struct {
29-
Type reflect.Type
30-
Value string
31-
}
32-
33-
func newUnmarshalTypeStrError(value string, rType reflect.Type) UnmarshalTypeError {
34-
return UnmarshalTypeError{
35-
Type: rType,
36-
Value: value,
37-
}
38-
}
39-
40-
func newUnmarshalTypeError(value any, rType reflect.Type) UnmarshalTypeError {
41-
return newUnmarshalTypeStrError(fmt.Sprintf("%v (%T)", value, value), rType)
42-
}
43-
44-
func (e UnmarshalTypeError) Error() string {
45-
return fmt.Sprintf("maxminddb: cannot unmarshal %s into type %s", e.Value, e.Type)
46-
}
10+
// UnmarshalTypeError is returned when the value in the database cannot be
11+
// assigned to the specified data type.
12+
UnmarshalTypeError = mmdberrors.UnmarshalTypeError
13+
)

0 commit comments

Comments
 (0)