Category: Uncategorized
-
Golang: String Format
%% prints a single % %b binary integer %c a character represented by the corresponding Unicode code point %d decimal integer %e scientific notation (mantissa/exponent), lowercase %E scientific notation (mantissa/exponent), uppercase %f decimal floating point, lowercase %F decimal floating point, uppercase %g the shortest representation of %e or %f %G the shortest representation of %E…
-
Kubernetes: Headless Service and Endpoints
Say you have Kubernetes node on 192.168.1.10 and a database node on 192.168.1.11. First, we create a dummy service: When you create a service you will also get an endpoint: To get my-db to point to 192.168.1.11. First, we need to edit the endpoint to point to 192.168.1.11. Add these lines to the end of…
-
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:
