Go method

Go methods are always bound to an object instance and implicitly take the instance as the first argument (known as the receiver).

func (receiverVariableName ReceiverType) MethodName(parameterList) (returnTypeList) {  
  //Method body  
}

Go methods are always used in conjunction with Go structs. This means that methods define behaviors that are specific to a given struct type. By defining methods on a struct, you can encapsulate both the data (the fields of the struct) and the operations that can be performed on that data (the methods) within a single type. This promotes encapsulation, a fundamental principle of object-oriented programming.

In the context of Go, it's important to note that Go does not have traditional classes in the sense that other languages like Java or C++ do. Instead, Go uses structs to group data, and methods to define behaviors that can operate on those structs. This approach is often referred to as "structured typing" or "compositional typing" in Go.

Take a break

πŸ‘‰πŸ‘‰πŸ‘‰ 【Jade Dynasty EP52】Xiao Bai fight scene of saving Gui Li