Think of it like this. The parameter before the function name can just become the first parameter of the function, so if you have a struct A then func (a *A) f1() {} is the same as func f2(a *A) {} That's all that's going on there. When you call &A{}.f1() it's the same as doing f2(&A{}). What this lets you do later is pass in A to interfaces that define an f1 function. type I interface { f1() } func wantsI(i I) { i.f1() } a := &A{} wantsI(a) This doesn't look all that impressive until you realize you can put I in another package, and that package doesn't have to depend on anything that knows A at all. Answer from i_should_be_coding on reddit.com
🌐
Go by Example
gobyexample.com › methods
Go by Example: Methods
Go supports methods defined on struct types · This area method has a receiver type of *rect
🌐
DEV Community
dev.to › jpoly1219 › structs-methods-and-receivers-in-go-5g4f
Structs, Methods, and Receivers in Go - DEV Community
January 30, 2023 - Methods are like functions, but they are bound to a certain type or object, which are called receivers. I honestly don't know why they are called methods, and it's probably because engineers are bad at naming things. Receivers do NOT have to be structs.
Discussions

better way to express a function in Go (Struct methods) - Stack Overflow
This is a function to traverse an array of Points. A Point is a struct with elements x and y of type int. The traverse function is called from another function with a value of dir. The if check at ... More on stackoverflow.com
🌐 stackoverflow.com
How to organize struct with lots of methods
It sounds like your Server struct is doing too many things. You could try to identify the different responsibilities of the components and separate them into their own type. This will allow you to decouple the different parts of your application, and future you will be thankful for that. Check out SOLID principles, specifically the first one, Single Responsibility Principle More on reddit.com
🌐 r/golang
8
6
April 20, 2022
Calling the embedding struct's overloaded method from the embedded struct - Technical Discussion - Go Forum
Consider this example: package main import ( "fmt" ) type A struct {} func (a *A) TheMethod() { fmt.Println("TheMethod (A's implementation)") } type B struct { A } func (b *B) TheMethod() { fmt.Println("TheMethod (B's implementation)") } func (a *A) TheMethodCallingTheMethod() { a.TheMethod() ... More on forum.golangbridge.org
🌐 forum.golangbridge.org
0
April 29, 2024
"Inheritance" of types in Golang
Golang does not have inheritance. More on reddit.com
🌐 r/golang
19
0
July 29, 2024
🌐
Reddit
reddit.com › r/golang › am i understanding go structs methods well?
r/golang on Reddit: Am I Understanding Go Structs Methods Well?
February 15, 2024 -

Hello everybody, it's me once again with a newbie question. Sorry for that, hehe.So, I was doing this course and saw that you can associate methods with structs. Or at least, that's what I think is happening here.Please, let's look at this code:

type EmployeeContract struct {
EmpID         int
Salary        float64
TaxPercentage float64

}

type FreelancerContract struct { EmpID int HourlyRate float64 HoursWorked int }

// 'EmployeeContract' Salary is the base salary - calculated taxes func (e EmployeeContract) CalculateSalary() float64 { return e.Salary - (e.TaxPercentage * e.Salary) }

// 'FreelancerContract' salary is the hourly rate * hours worked -- they declare taxes themselves func (f FreelancerContract) CalculateSalary() float64 { return f.HourlyRate * float64(f.HoursWorked) }

type SalaryCalculator interface { CalculateSalary() float64 }

At the beginning, I didn't understand what was going on. Why is there a parameter before the name of the method in CalculateSalary()? But then I realized it was not a parameter. It was more like an association to the struct FreelancerContract. (Am I getting this right?)

Go is kinda hard for me, even though I already know how to code and stuff, because its syntax is not really something I'm used to. A few days ago, I barely understood pointers, but now I understand them, thanks to you guys.

What I like to do is to "compare" the Go code to Java, Python, or the languages I'm used to.

Please tell me if this is something I should do or if it's making my learning worse.

But this is my interpretation:FreelancerContract is like a Java or C# class, and CalculateSalary() is one of its methods. So in Java, for example, it may look like this:

public class EmployeeContract {
private int empID;
private double salary;
private double taxPercentage;

public EmployeeContract(int empID, double salary, double taxPercentage) {
    this.empID = empID;
    this.salary = salary;
    this.taxPercentage = taxPercentage;
}

public double calculateSalary() {
    return salary - (taxPercentage * salary);
}

}

public class FreelancerContract { private int empID; private double hourlyRate; private int hoursWorked;

public FreelancerContract(int empID, double hourlyRate, int hoursWorked) {
    this.empID = empID;
    this.hourlyRate = hourlyRate;
    this.hoursWorked = hoursWorked;
}

public double calculateSalary() {
    return hourlyRate * hoursWorked;
}

}

In Go by Example, they define this type of methods like this:

Methods can be defined for either pointer or value receiver types.Go automatically handles conversion between values and pointers for method calls. You may want to use a pointer receiver type to avoid copying on method calls or to allow the method to mutate the receiving struct.

Please correct me if i'm wrong or if i'm missing something. I still don't get it 100%

I'm sorry that the code doesn't appear formatted, for some reason, even if I edit it, Reddit places it like this. Maybe I should have written it in markdown :(

Top answer
1 of 2
4
Think of it like this. The parameter before the function name can just become the first parameter of the function, so if you have a struct A then func (a *A) f1() {} is the same as func f2(a *A) {} That's all that's going on there. When you call &A{}.f1() it's the same as doing f2(&A{}). What this lets you do later is pass in A to interfaces that define an f1 function. type I interface { f1() } func wantsI(i I) { i.f1() } a := &A{} wantsI(a) This doesn't look all that impressive until you realize you can put I in another package, and that package doesn't have to depend on anything that knows A at all.
2 of 2
1
Why is there a parameter before the name of the method in CalculateSalary()? But then I realized it was not a parameter. It totally is a parameter - just a special one. It's called the method receiver. If you're familiar with other OO languages, methods have a special variable in scope: this or self. This is a hidden parameter that refers to the specific object the method is operating on. That "parameter" before the method name, that's Go's version of this, only it's explicit. You get to choose whether it's value or pointer semantics, and get to choose the name. Here's some code to illustrate: c := EmployeeContract{} // You can call a method right from a type EmployeeContract.CalculateSalary(c) // Or a variable c.CalculateSalary() In fact, look at EmployeeContract.CalculateSalary: you specified no parameters, but it expects one: the instance of the EmployeeContract. That's because when you call c.CalculateSalary(), under the hood it becomes EmployeeContract.CalculateSalary(c).
🌐
Medium
medium.com › @danielabatibabatunde1 › simplifying-structs-methods-and-interfaces-in-golang-e86a0c4618aa
Simplifying Structs, Methods and Interfaces in Golang. | by Abati Babatunde Daniel | Medium
March 7, 2025 - Golang has the ability to address most OOP concepts by implementing Structs which are used to define the data structures of your project and model real-world entity — similar to the way classes work. Go defining methods for which they are simply functions relating to structs to Interfaces which defines a set of method signatures (basically means any type that has these specific methods belongs to me) — polymorphism.
🌐
GeeksforGeeks
geeksforgeeks.org › go language › go-structs-methods-and-receivers
Go - Structs, Methods, and Receivers - GeeksforGeeks
July 23, 2025 - Both structs in Go and classes in other OOP languages group related data (fields) together. Both have the ability to define methods for their behavior.
Find elsewhere
🌐
CodeSignal
codesignal.com › learn › courses › go-structs-basics-revision › lessons › go-structs-and-methods-an-introduction
Go Structs and Methods: An Introduction
Accessing struct fields involves the dot (.) operator, and initialization occurs using composite literals or individual assignments. ... Differently from other OOP languages, in Go methods are simply functions with a receiver argument. Receiver functions in Go feature the special receiver ...
🌐
Learn Go with Tests
quii.gitbook.io › learn-go-with-tests › go-fundamentals › structs-methods-and-interfaces
Structs, methods & interfaces | Learn Go with tests
February 26, 2026 - Declaring structs to create your own data types which lets you bundle related data together and make the intent of your code clearer · Declaring interfaces so you can define functions that can be used by different types (ad hoc polymorphism) Adding methods so you can add functionality to your data types and so you can implement interfaces
🌐
Recursionist
recursionist.io › learn › languages › go › oop › method
Go言語のメソッドを解説 - Recursion
type Person struct { name string age int } func (p Person) IncreaseAge() { p.age++ } p := Person{name: "John", age: 30} p.IncreaseAge() fmt.Println(p.age) // 30
🌐
Satoshun
satoshun.github.io › 2016 › 08 › go-struct-method
Golang: structで宣言したメソッドを明示的に呼び出す - stsnブログ
August 1, 2016 - Goでは, 宣言したtypeにメソッドを定義することが出来ます. 典型的な用途としては, structでデータ型を宣言して, それにメソッドを定義する使い方だと …
🌐
KodeKloud Notes
notes.kodekloud.com › docs › Golang › Struct-Methods-and-Interfaces › Passing-Structs-to-Functions › page
Passing Structs to Functions - KodeKloud
This tutorial explains how to pass structs to functions in Go using passing by value and passing by reference methods.
🌐
Reddit
reddit.com › r/golang › how to organize struct with lots of methods
r/golang on Reddit: How to organize struct with lots of methods
April 20, 2022 -

In Go is there a recommended/idiomatic way to logically organize/break up a massive struct with 1000+ lines of methods into separate files?

I have a Server struct for a gRPC server that has a ton of different methods for things like:

- interacting with Redis

- gRPC request handlers running a distributed election algorithm to select a leader/coordinator for a group of nodes

- handling data replication

Many of these methods are are server side gRPC request handlers, while others create gRPC clients to interact with other server nodes.

I am wondering if there is some recommended way to break these methods up into logical groups. Can I put the election methods in one file, replication methods in another, all of them with the same (s* Server) receiver?

🌐
Scaler
scaler.com › home › topics › golang › methods on non-struct type
Methods on Non-Struct Type- Scaler Topics
May 4, 2023 - The only difference between a Go method and a Go function is an extra argument that is added after the func keyword to specify the method's receiver. The receiver argument of the method has a name and a type.
🌐
Medium
medium.com › @bramahendramahendra1 › introduction-to-structs-and-methods-in-golang-842f0c6e8e2a
Introduction to Structs and Methods in Golang | by Brama Mahendra | Medium
September 19, 2023 - You can access the fields in a struct using the dot . operator: ... Methods are functions that are executed in the context of an instance of a type.
🌐
Move Book
move-book.com › move-basics › struct-methods.html
Struct Methods
Learn Move language fundamentals: types, modules, functions, structs, abilities, generics, and control flow for Sui smart contracts.
🌐
Go Forum
forum.golangbridge.org › technical discussion
Calling the embedding struct's overloaded method from the embedded struct - Technical Discussion - Go Forum
April 29, 2024 - Consider this example: package main import ( "fmt" ) type A struct {} func (a *A) TheMethod() { fmt.Println("TheMethod (A's implementation)") } type B struct { A } func (b *B) TheMethod() { fmt.Println("TheMethod (B's implementation)") } func (a *A) TheMethodCallingTheMethod() { a.TheMethod() } func main() { foo := B{} foo.TheMethodCallingTheMethod() } The output is TheMethod (A's implementation) which is sort-of understandable.
🌐
DEV Community
dev.to › leadpresence › how-to-to-attach-a-function-to-a-struct-in-golang-1o3o
How to to attach a function to a struct in Golang - DEV Community
April 1, 2025 - In such OOP languages you create such methods in the class scope such as : class ClassName{ .... function functionName(){ // perform action } } In go you first create a struct then you can attach receivers to perform specific actions for the struct.
🌐
Codedamn
codedamn.com › news › golang
Structs and Methods in Go: A Journey Through the Land of Code
March 6, 2023 - In the code above, we’ve created an instance of the Person struct and assigned values to its fields. It’s that simple! Methods in Go are like functions, but they’re bound to a specific type.