Skip to content

Instantly share code, notes, and snippets.

View by-sabbir's full-sized avatar
🎯
Focusing

Sabbir Ahmed by-sabbir

🎯
Focusing
View GitHub Profile
@by-sabbir
by-sabbir / pointer_vs_value_receiver.go
Created October 28, 2022 12:32
pointer vs value receiver method in go
/*
user object:
{
"id": "some-user-id",
"email": [email protected],
"is_verified": false
}
*/
package main
@by-sabbir
by-sabbir / function-method.go
Created October 28, 2022 12:04
function and method in go
/*
user object:
{
"id": "some-user-id",
"email": [email protected],
"is_verified": false
}
*/
package main
@by-sabbir
by-sabbir / main.go
Created October 28, 2022 11:48
go defer timeit
package main
import (
"fmt"
"time"
)
var timeit = func() func() {
start := time.Now()
return func() {
diff --git a/sequential.txt b/concurrent.txt
similarity index 56%
rename from sequential.txt
rename to concurrent.txt
index 7635f4e..0dd617e 100644
--- a/sequential.txt
+++ b/concurrent.txt
@@ -9,18 +9,18 @@ Timeout: 10s
RESULT
@by-sabbir
by-sabbir / concurrentwrite
Created October 15, 2022 15:31
concurrent write to the databse
...
rowCh := make(chan *sql.Rows, 1)
errCh := make(chan error, 1)
go func() {
row, err := db.Client.QueryContext(
ctx,
qs,
...
)
@by-sabbir
by-sabbir / sequentialwrite
Created October 15, 2022 15:14
sequential write to the databse
...
row, err := db.Client.QueryContext(
ctx,
qs,
...
)
... // check for error and close the row
package consul
import (
"fmt"
"log"
consulApi "github.com/by-sabbir/consul-kv-discovery/pkg/consul"
)
type ServiceDefinition struct {
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
consulApi "github.com/by-sabbir/consul-kv-discovery/pkg/consul"
)
package consul
import (
"log"
"github.com/hashicorp/consul/api"
)
type KVClient struct {
*api.KV
@by-sabbir
by-sabbir / docker-compose.yml
Last active October 3, 2022 11:20
single server consul docker compose
version: "3"
services:
consul:
image: hashicorp/consul:1.10.0
restart: always
volumes:
- ./conf/server.json:/consul/config/server.json:ro
ports:
- 8500:8500