4

I am working on a library / wrapper for mysql in go. For usage of my API I imagined something like:

model
    .Select("INTERNAL_ID")
    .Select("EXTERNAL_ID")
    .Find(1);

With, as example, the following functions:

func (model SQLModel) Select(selectString string) SQLModel 
func (model SQLModel) Find(id int) interface{}

The problem is that I can't break my function calls into multiple lines as go/fmt complains: syntax error: unexpected ., expecting } at every break.

Now, I could go :

model.Select("INTERNAL_ID").Select("EXTERNAL_ID").Find(1)

But as the API grows (where, join, sum, etc, ...) it'll rapidly become hard to read.

So, how can I split function calls in GO ?

Thanks,

Mathieu Nls
  • 2,285
  • 2
  • 17
  • 32

1 Answers1

13

The dots must be at the end of line:

model.
    Select("INTERNAL_ID").
    Select("EXTERNAL_ID").
    Find(1)
alexbt
  • 16,415
  • 6
  • 78
  • 87