Skip to content

Instantly share code, notes, and snippets.

@manjeettahkur
manjeettahkur / slice_pass_by_ref.go
Created January 11, 2023 08:34
In go language everything is pass by value even slice. but in slice case slice header pass by value so both headers point to the same back array
package main
import "fmt"
func main() {
a := []byte{'A', 'M', 'N', 'J', 'E', 'E', 'T'}
b := s(a)
b[0], b[1] = b[1], b[0]
fmt.Println(string(a))
@manjeettahkur
manjeettahkur / mutex.go
Created January 11, 2023 08:25
Which snippet of code acquire more locks
package main
import (
"fmt"
"sync"
"time"
)
func main() {
var mu sync.Mutex
// Slice rules in go programming language
starting cap growth factor
256 2.0
512 1.63
1024 1.44
2048 1.35
4096 1.30
package main
1. Query to your local database to check that cloudtrail data is present in the local database.
IF yes
// It means you have stored some data from cloudtrail before.
// And now you are going to do request to cloudtrail for new trail events.
// Note - At a time of the first request you don't have a token (i.e. next-token)
GOTO Step 3
ELSE
package main
import (
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"strings"
@manjeettahkur
manjeettahkur / jsonUnmarshalText.go
Created July 6, 2022 10:05
unmarshal text in go programming language
package main
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"log"
)
@manjeettahkur
manjeettahkur / add_array_concurrent.go
Last active June 5, 2022 09:36
This is an example using the Go programming language. With channels With Waitgroups and With Sequentials
func addConcurrent(numbers []int) int {
var v int64
goroutines := runtime.NumCPU()
totalNumbers := len(numbers)
lastGoroutine := goroutines - 1
stride := totalNumbers / goroutines
var wg sync.WaitGroup
wg.Add(goroutines)
@manjeettahkur
manjeettahkur / .golangci.yaml
Created June 1, 2022 01:57
Code conventions, Practice and Tooling Group -- Linter Settings
linters-settings:
govet:
check-shadowing: true
settings:
printf:
funcs:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
@manjeettahkur
manjeettahkur / maptostruct.go
Created May 30, 2022 13:00
convert map to struct in go programming language
package main
import (
"fmt"
"reflect"
)
func main() {
source := map[string]any{
"A": 23,
data, _ := json.Marshal(context.WithValue(context.Background(), "a", "b"))
fmt.Println(string(data))