Original post

Why does

builder := aliasBuilder{}
 return builder.From(c.GetString("from")).To(c.GetString("to"))

compile and work but

return aliasBuilder{}.From("this").To("that") //<- does not work?

and if there is a way to make the one line version “work” what would that syntax look like?

Below is the code in more context.

type Alias struct {
        From uuid.UUID
        To   uuid.UUID 
}

func Create(c *gin.Context) domain.Alias {
        builder := aliasBuilder{}
        return builder.From(c.GetString("from")).To(c.GetString("to"))
}

type aliasBuilder struct {
        from uuid.UUID
        tb toBuilder
}

type toBuilder struct {
        fb *aliasBuilder
        touid uuid.UUID
}

type to interface {
        To(to string) uuid.UUID
}

type from interface {
        From(from string) to
}

func (fb *aliasBuilder) From(from string) *toBuilder {
        fb.from = uuid.FromStringOrNil(from)
        fb.tb = toBuilder{fb: fb}
        return &fb.tb
}

func (tb *toBuilder) To(tot string) domain.Alias {
        tb.touid = uuid.FromStringOrNil(tot)
        return domain.NewAlias(tb.fb.from, tb.touid)
}