Skip to content

Instantly share code, notes, and snippets.

View nikzayn's full-sized avatar
🎯
Delving more into Cloud Native Space

Nikhil Vaidyar nikzayn

🎯
Delving more into Cloud Native Space
View GitHub Profile
@nikzayn
nikzayn / usingpointersinstruct.go
Created May 25, 2023 08:09
Example of using omitempty tag using pointers in structs
package main
import (
"encoding/json"
"fmt"
)
type BMI struct {
Height int
Weight int
@nikzayn
nikzayn / withoutusingpointersinstruct.go
Created May 25, 2023 08:07
Example of using omitempty tag wihout using pointers in structs
package main
import (
"encoding/json"
"fmt"
)
type BMI struct {
Height int
Weight int
@nikzayn
nikzayn / withomitempty.go
Last active May 25, 2023 05:27
Example to show the output of json using omitempty tag
package main
import (
"encoding/json"
"fmt"
)
type Person struct {
Name string
Age int `json:",omitempty"`
@nikzayn
nikzayn / withoutomitempty.go
Last active May 25, 2023 05:23
Example to show the output of json without using omitempty tag
package main
type Person struct {
Name string
Age int
}
func main() {
p := Person{
Name: "Nikhil",
@nikzayn
nikzayn / mapswithpointer.go
Last active May 17, 2023 21:00
In this file, we are adding and deleting 10 million elements in a map and see how it works.
package main
import (
"fmt"
"runtime"
)
func main() {
n := 10000000
m := make(map[int]*[128]byte)
@nikzayn
nikzayn / mapswithoutpointer.go
Last active May 17, 2023 21:00
In this file, we are adding and deleting 10 million elements in a map and see how it works.
package main
import (
"fmt"
"runtime"
)
func main() {
n := 10000000
m := make(map[int][128]byte)
@nikzayn
nikzayn / polymorphism.go
Created June 16, 2022 11:37
A brief example of how we can replicate the principle of polymorphism.
package polymorphism
// Developer struct
type Developer struct {
Fuel string
CanImplement bool
}
// Interface to add collection of methods
type Tasks interface {
@nikzayn
nikzayn / composition.go
Last active June 16, 2022 08:27
A brief example of how we can achieve composition in go. Composition is not anything like inheritance it's just embed one struct to another to maintain data inheritance in it's own way.
// Person struct
type Person struct {
FirstName string
LastName string
Age int
TotalExperience int
}
// Person struct embedded in Job struct
type Job struct {
@nikzayn
nikzayn / details.go
Last active June 15, 2022 13:28
A brief example of how we can use principle of encapsulation in Go
package details
import (
fmt
person "github.com/nikzayn/encapsulation/user"
)
func main() {
fmt.Println(person.GetDateOfBirth()) // 1989
fmt.Println(person.getFoodStatus()) // Not declared by package because it is small caps