Your cart is currently empty!
Author: Website Admin
Golang: Append via Function Receiver
Create new type that holds slice of user struct. Create function receiver for our new type. In our main function we can use it to add user struct to the slice.
Golang: Conditional with Empty Struct
This will generate an error The correct way to write is to enclose struct with parentheses (User{}) However, this works
Vim: Insert Mode
Pressing Ctrl-o in insert mode will turn Vim into normal mode for one set of command. Pressing Esc in insert mode will turn Vim into normal mode permanently.
Kubernetes: Node Cordon vs. Node Drain
Node Cordon This will mark the node as unschedulable. New pod will not be scheduled to be deployed on this node. Existing pods still run on this node until the next reschedule. Node Uncordon This will mark the node as schedulable. Node Drain This will mark the node as unschedulable and at the same time…
Golang: Byte and Bytes
References: How to Create a Byte Array in Golang (askgolang.com) GoLang Byte Array to String – GoLang Docs GoLang bytes – variable and package – GoLang Docs
Golang: New Keyword
In Golang there are several ways to create instance of struct. Say we have this Person struct: We can instantiate this struct with: When using the new keyword you will get reference of the struct in return. References:
Golang: HTTP Server
To test, you can run: It should response one of the three methods (or all three). UPDATE: Before Golang version 1.22, you only can define “path” as the first argument of http.HandleFunc. But, starting from Golang version 1.22 the pattern becomes: Please check here for more information about the new pattern https://pkg.go.dev/net/http#hdr-Patterns. References:
Golang: Printing Struct
Say we have a struct like this: Then in your main function you have: Printing the struct using print function: Printing the struct using json.MarshalIndent function: References: