Internalize id.ContentURI Valuer
Removes dependency on custom mautrix-go
This commit is contained in:
29
types/contentURI.go
Normal file
29
types/contentURI.go
Normal file
@ -0,0 +1,29 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
type ContentURI struct {
|
||||
id.ContentURI
|
||||
}
|
||||
|
||||
func (m *ContentURI) Scan(value interface{}) error {
|
||||
bytes, ok := value.([]byte)
|
||||
if !ok {
|
||||
println(len(bytes))
|
||||
//return errors.New(fmt.Sprint("Failed to unmarshal value:", value))
|
||||
}
|
||||
if len(bytes) == 0 {
|
||||
uri, _ := id.ParseContentURI("")
|
||||
*m = ContentURI{uri}
|
||||
return nil
|
||||
}
|
||||
return m.UnmarshalText(bytes)
|
||||
}
|
||||
|
||||
func (m ContentURI) Value() (driver.Value, error) {
|
||||
return m.String(), nil
|
||||
}
|
Reference in New Issue
Block a user