It is possible, but not with your example. In gorm the chaining happens since every method in chain returns the type *DB. Which has next method in chain.
Here you need to use something like:
f.ToString(f.GetID())
Sometimes, you can encounter custom types, which allows you to expand the base type with new methods e.g.:
package main
import (
"fmt"
"strconv"
)
type ID int
func (id ID) String() string {
return strconv.Itoa(int(id))
}
type Foo struct {
id ID
name string
}
func (f *Foo) GetName() string {
return f.name
}
func (f *Foo) GetID() ID {
return f.id
}
func main() {
f := &Foo{id: ID(4), name: "name"}
fmt.Println(f.GetID().String()) // Prints 4.
}