This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package unmarshal | |
import ( | |
"fmt" | |
"reflect" | |
) | |
// keyValuePairs takes in map[string]interface{} as interface{} and returns map[string]string | |
// In simpler words, it takes map of uncertain levels and returns the leaf key-value pairs. | |
func keyValuePairs(m interface{}) map[string]string { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package formattedTime | |
import ( | |
"fmt" | |
"regexp" | |
"time" | |
) | |
type FormattedTime string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io/ioutil" | |
"time" | |
) | |
func main() { | |
// Not handling any errors since just demonstration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package fibonacci | |
import "sync" | |
func Fibonacci(n int) int { | |
var wg sync.WaitGroup | |
var mu sync.Mutex | |
var a, b int = 0, 1 | |
wg.Add(n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package randomStrings | |
import ( | |
"context" | |
"math/rand" | |
"time" | |
) | |
// randInt is local function that returns a random integer between provided min, max. | |
func randInt(min int, max int) int { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"net/http" | |
"os" | |
) | |
// HashMap is the implementation of a hash map in Go | |
type HashMap map[interface{}]interface{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Channel is a custom type to hold channel and context variables. | |
type Channel struct { | |
// Only unexported fields | |
ch chan interface{} | |
ctx context.Context | |
cancelFunc context.CancelFunc | |
} | |
// runProducer is creates a separate goroutine that continuously produces given message. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
// PrimeGenerator creates a generator goroutine that returns prime numbers, least first | |
func PrimeGenerator(close <-chan int) chan int { | |
var current int | |
var flag bool | |
ch := make(chan int) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Character struct { | |
Name string `json:"name"` | |
Designation []string `json:"designation"` | |
Age int `json:"age"` | |
Moves []Move `json:"moves"` | |
} | |
type Move struct { | |
Name string `json:"move"` | |
Power int `json:"power"` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var jsonData []byte | |
jsonData, err = json.Marshal(data) | |
if err != nil { | |
// Handle Error | |
} | |
fmt.Println(jsonData) // JSON data in bytes | |
fmt.Println(string(jsonData)) // String for format verification |
OlderNewer