Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
KI & AI VideosJulian Goldie SEO: I Ranked in Google + Grok in 24 Hours(22.09.2026 um 15:00 Uhr)
IT Security Toolsshannon v3.3.0(22.09.2026 um 13:56 Uhr)
IT Security Toolspentest-harness(22.09.2026 um 14:31 Uhr)
Reverse EngineeringPureRAT-msbuild.exe--C2-Extraction--Net-Evasion-Analysis(22.09.2026 um 15:06 Uhr)
IT Security NachrichtenBeware these fake websites selling subscriptions to AI assistants(22.09.2026 um 15:11 Uhr)
IT Security NachrichtenDORA Year Two: Reicht die SOC-Sicht für Echtzeit-Angriffe?(22.09.2026 um 14:54 Uhr)
IT Security NachrichtenDORA Year Two: Netzwerk-Sicht entscheidet über SOC-Fähigkeiten(22.09.2026 um 15:27 Uhr)
IT Security NachrichtenIT Security News Hourly Summary 2026-09-22 15h : 19 posts(22.09.2026 um 15:00 Uhr)
KI & AI VideosJulian Goldie SEO: I Ranked in Google + Grok in 24 Hours(22.09.2026 um 15:00 Uhr)
IT Security Toolsshannon v3.3.0(22.09.2026 um 13:56 Uhr)
IT Security Toolspentest-harness(22.09.2026 um 14:31 Uhr)
Reverse EngineeringPureRAT-msbuild.exe--C2-Extraction--Net-Evasion-Analysis(22.09.2026 um 15:06 Uhr)
IT Security NachrichtenBeware these fake websites selling subscriptions to AI assistants(22.09.2026 um 15:11 Uhr)
IT Security NachrichtenDORA Year Two: Reicht die SOC-Sicht für Echtzeit-Angriffe?(22.09.2026 um 14:54 Uhr)
IT Security NachrichtenDORA Year Two: Netzwerk-Sicht entscheidet über SOC-Fähigkeiten(22.09.2026 um 15:27 Uhr)
IT Security NachrichtenIT Security News Hourly Summary 2026-09-22 15h : 19 posts(22.09.2026 um 15:00 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

The Golang Trinity: Functions, Methods, Interfaces

Function: Does something with inputs Method Does something attached to a type Interface Says what methods a type must have A method is a function with a receiver. An interface is a set of method signatures. If a type has those methods…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

Function: Does something with inputs

Method Does something attached to a type

Interface Says what methods a type must have



A method is a function with a receiver.

An interface is a set of method signatures.

If a type has those methods → it satisfies the interface. Automatically.



No implements. No inheritance. Just behavior.



// Function

func Add(a, b int) int { return a + b }



type Counter struct{ val int }



// Method (receiver is the "attachment")

func (c Counter) Add(n int) int { return c.val + n }




  1. Function vs. Method
    // Function
    func Add(a, b int) int { return a + b }



type Counter struct{ val int }



// Method (receiver is the "attachment")

func (c Counter) Add(n int) int { return c.val + n }

Same logic. Different style.

Use functions for stateless operations.

Use methods when behavior belongs to a type.




  1. The Interface Glue



type Stringer interface {

String() string

}



type User struct{ Name string }



// User now implements Stringer automatically

func (u User) String() string { return u.Name }



func Print(s Stringer) { fmt.Println(s.String()) }



func main() {

Print(User{Name: "Alice"}) // Works!

}

Key: The function Print doesn't care about User. It cares about the String() method.




  1. The Twist: Functions Can Be Interfaces
    This is the pattern that confuses people.



// An interface

type Handler interface {

Handle(string)

}



// A function type

type HandlerFunc func(string)



// The trick: attach the Handle method to the function type

func (f HandlerFunc) Handle(s string) {

f(s) // calls itself

}



// Now any function with signature func(string) works as a Handler

func Log(s string) { fmt.Println("LOG:", s) }



func main() {

var h Handler = HandlerFunc(Log)

h.Handle("test") // LOG: test

}

Why is this useful?

It lets you use simple functions where interfaces are expected.

The standard http.HandlerFunc works exactly like this.




  1. Putting It All Together
    go
    type Greeter interface { Greet() string }



type Person struct{ Name string }

func (p Person) Greet() string { return "Hi, " + p.Name }



type GreetFunc func() string

func (gf GreetFunc) Greet() string { return gf() }



func Party(g Greeter) { fmt.Println(g.Greet()) }



func main() {

Party(Person{Name: "Bob"}) // Method

Party(GreetFunc(func() string { // Function as interface

return "Surprise!"

}))

}

The Golden Rule

Accept interfaces, return structs.



Functions orchestrate.



Methods define behavior on types.



Interfaces abstract the what from the how.



Your Turn

What's your favorite small interface from the standard library?

io.Reader? fmt.Stringer? http.Handler?



Drop it below 👇

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten The Golang Trinity: Functions, Methods, Interfaces

Thematisch verwandte Begriffe: Golang, Trinity, Functions, Methods · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-87082 | Net::IDN::Punycode versions before 2.590 for Perl hang, crash or return …
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick