Skip to content

Instantly share code, notes, and snippets.

View dxavx's full-sized avatar
🏠
Working from home

dxavx dxavx

🏠
Working from home
View GitHub Profile
@dxavx
dxavx / pointer_array.go
Last active October 4, 2021 19:01
Passing pointers to the slice function
package main
import "fmt"
func main() {
var a []*int
d1 := 100
d2 := 200
d3 := 300
@dxavx
dxavx / json.go
Created July 18, 2021 12:47
json_type unmarshal interface
package main
import (
"encoding/json"
"errors"
"fmt"
"io"
"strings"
"time"
)
@dxavx
dxavx / context_cancel.go
Created July 18, 2021 12:04
context cancel example
package main
import (
"context"
"fmt"
"log"
"net"
"os"
"os/signal"
"time"
@dxavx
dxavx / json_switch_type.go
Last active May 28, 2021 20:59
json swtch type
kv := map[string]interface{}{}
kv["A"] = 1
kv["B"] = "XXX"
kv["C"] = true
for k, v := range kv {
switch v.(type) {
case int:
fmt.Println(k, "INT ", v)
case string:
@dxavx
dxavx / JSON byte decoder
Last active April 25, 2021 15:23
parsing.go
// parsing JSON by type
func main() {
var Data = []byte(`{"count": 2000}`)
var result map[string]interface{}
var decoder = json.NewDecoder(bytes.NewBuffer(Data))
decoder.UseNumber()
if err := decoder.Decode(&result); err != nil {
@dxavx
dxavx / map.go
Last active January 17, 2021 13:08
Hash map
// Make
m := make(map[string]int)
m1 := new(map[string]int)
var m2 map[string]int
m3 := map[string]int{"apple": 99, "orange": 100}
// Insert data
m3["carrot"] = 101
// Delete data
@dxavx
dxavx / sync-once.go
Created May 7, 2020 07:56
sync.Once , one exec block code.
package main
import "sync"
type Init struct {
message string
init sync.Once
}
func (d *Init) Run() {
@dxavx
dxavx / worker.go
Created May 6, 2020 18:23
workers wait group and mutex
package main
import (
"fmt"
"sync"
)
var i int
func main(){
@dxavx
dxavx / mutex.go
Created March 11, 2020 17:29
mutex simple
package main
import "sync"
var (
mu sync.Mutex
balance int
)
func Deposit(amount int) {
@dxavx
dxavx / interface.go
Created March 8, 2020 07:14
interface
package main
import (
"fmt"
"log"
"net/http"
)
func main() {
db := database{"AAA": 50, "BBB": 5 , "CCC" : 77}