package main
import "fmt"
type cache map[string]map[string]map[string]string
var localizationParseCache cache
func main() {
localizationParseCache = cache{
"test": {
"testing": {
"test": "tt",
},
},
}
localizationParseCache["test"]["testing"]["test2"] = "ttt"
fmt.Println(localizationParseCache)
}
package main
import (
"fmt"
)
func min(a, b int) int {
if a < b {
return a
}
return b
}
func splitIntoChunks(s string, chunkLength int) []string {
length := len(s)
chunksCount := length / chunkLength
if length%chunkLength != 0 {
chunksCount += 1
}
chunks := make([]string, chunksCount)
for i := range chunks {
from := i * chunkLength
to := min(length, from+chunkLength)
chunks[i] = s[from:to]
}
return chunks
}
func main() {
s := "aaabbbcccdddeeee"
fmt.Println(splitIntoChunks(s, 3))
}
package main
import (
"fmt"
"sync"
"time"
)
var wg sync.WaitGroup
func worker(id int, jobs <-chan int, results chan<- int) {
defer wg.Done()
for j := range jobs {
fmt.Println("worker", id, "processing job", j)
time.Sleep(time.Second)
results <- j
}
}
func main() {
jobs := make(chan int, 100)
results := make(chan int, 100)
for w := 1; w <= 5; w++ {
wg.Add(1)
go worker(w, jobs, results)
}
for j := 1; j <= 10; j++ {
jobs <- j
}
close(jobs)
wg.Wait()
close(results)
for msg := range results {
fmt.Println("worker", msg)
}
fmt.Println("main finished")
}
map[string]interface{}
type M map[string]interface{}
obj := M{
"hello": "world",
"hello2": []M{
{"a": 1},
{"b": 2},
},
"c": M{
"subC": 3,
},
}