Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Break multi line function call [duplicate]

Tags:

go

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,

like image 207
Mathieu Nls Avatar asked Nov 16 '25 01:11

Mathieu Nls


1 Answers

The dots must be at the end of line:

model.
    Select("INTERNAL_ID").
    Select("EXTERNAL_ID").
    Find(1)
like image 80
alexbt Avatar answered Nov 17 '25 19:11

alexbt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!