Тёмный

#15 Mastering Golang Structs Part - 3: A Comprehensive Guide | From Basics to Advanced  

Code with Yogesh
Подписаться 359
Просмотров 125
50% 1

In Go, a struct is a composite data type that groups together variables under a single name. These variables are called fields. Each field has a name and a type. Structs are used to create complex data types that group different properties together.
Source code: github.com/yyogesh/golang-lea...
Go (Golang) does not support traditional class-based inheritance as seen in languages like Java or C++. Instead, Go uses a combination of structs and interfaces to achieve polymorphism and code reuse. This is often referred to as "composition over inheritance."
Here's how you can achieve similar functionality to inheritance in Go using composition and interfaces.
Composition
Composition involves creating complex types by combining simpler ones. You can embed structs within other structs to reuse code and create more complex structures.
Golang Tagging
In Go (Golang), struct tags are annotations that can be added to the fields of a struct to provide additional information about how those fields should be processed. These tags are often used in conjunction with packages like encoding/json or gorm, which use the tags to customize the behavior of encoding/decoding, validation, or database interactions.
json:"name" specifies that the Name field should be encoded as "name" in the JSON output.
json:"-" specifies that the Password field should be omitted from the JSON output.

Опубликовано:

 

30 июн 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии    
Далее
Object Oriented Programming (OOP) in C++ Course
1:30:26
Ouch.. 🤕
00:30
Просмотров 8 млн
JWT Authentication in Go (Gin/Gorm)
35:26
Просмотров 67 тыс.
Rust Tutorial Full Course
2:35:11
Просмотров 529 тыс.
Golang: The Last Interface Explanation You'll Ever Need
17:58
PhpStorm for Laravel Developers - 3 Hour Full MasterClass
2:35:29