More specifically, I now understand the revel framework and found a piece of code that I don’t understand: http://pastebin.com/ce5M9Mfn. Specifically, I am worried about the first two lines of the function - they have a strange syntax. The first part (the letter c) is ... call it an object, of course. The next part - apparently, some kind of package, included in the "controllers". Then comes the function that does something. But what after it? one more function?

package controllers import ( "github.com/robfig/revel" "revel/app/models" ) ...... func (c Application) Hello(myName string) revel.Result { c.Validation.MinSize(myName, 3).Message("Your name is not long enough!") c.Validation.Required(myName).Message("Your name is required!") if c.Validation.HasErrors() { c.Validation.Keep() c.FlashParams() return c.Redirect(Application.Index) } return c.Render(myName) } 
  • In pastebin is empty, paste the code here. - qnub

1 answer 1

What you see is Method declarations .

Parsing in pieces

 func - это ключевое слово, куда же без него. (c Application) это "Receiver" - получатель. Hello - а это уже имя метода (myName string) и его параметры revel.Result и тип. 

if I understand go, then Receiver is what in other languages ​​is called this , self .

  • No, this is understandable. The lines below are not clear to me, these are: c.Validation.MinSize (myName, 3) .Message ("Your name is not long enough!") C.Validation.Required (myName) .Message ("Your name is required!" ) That's what I said about them. - dmitro_zx
  • one
    I see nothing surprising in them. the string c.Validation.MinSize (myName, 3) .Message ("Your name is not long enough!") can be rewritten as x1: = c.Validation x2: = x1.MinSize (myName, 3) x2.Message ("Your name is not long enough! ") The usual construction for many languages. c.Validation returns an object. it calls its own method, which again returns an object. Types x1 and x2 still need to be clarified. - KoVadim
  • thanks, now everything is clear. - dmitro_zx