Skip to content

Commit

Permalink
fix(schema): net.IPNet(not ptr) is not implement fmt.Stringer
Browse files Browse the repository at this point in the history
  • Loading branch information
Aoang committed Oct 14, 2024
1 parent 3abcdc4 commit 889af78
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion schema/append_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package schema
import (
"database/sql/driver"
"fmt"
"net"
"reflect"
"strconv"
"strings"
Expand Down Expand Up @@ -98,7 +99,9 @@ func appender(dialect Dialect, typ reflect.Type) AppenderFunc {
return appendTimeValue
case timePtrType:
return PtrAppender(appendTimeValue)
case ipType, ipNetType, netipPrefixType, netipAddrType:
case ipNetType:
return appendIPNetValue
case ipType, netipPrefixType, netipAddrType:
return appendStringer
case jsonRawMessageType:
return appendJSONRawMessageValue
Expand Down Expand Up @@ -244,6 +247,11 @@ func appendTimeValue(fmter Formatter, b []byte, v reflect.Value) []byte {
return fmter.Dialect().AppendTime(b, tm)
}

func appendIPNetValue(fmter Formatter, b []byte, v reflect.Value) []byte {
ipnet := v.Interface().(net.IPNet)
return fmter.Dialect().AppendString(b, ipnet.String())
}

func appendStringer(fmter Formatter, b []byte, v reflect.Value) []byte {
return fmter.Dialect().AppendString(b, v.Interface().(fmt.Stringer).String())
}
Expand Down

0 comments on commit 889af78

Please sign in to comment.