Skip to content

Instantly share code, notes, and snippets.

View shazadbrohi's full-sized avatar

Shazad Brohi shazadbrohi

  • VMware
  • Austin, TX
View GitHub Profile
package main
import ("fmt"
"net/http"
)
func main(){
rootHttpHandler := func(writer http.ResponseWriter, request *http.Request) {
fmt.Fprintf(writer, "Request Method: %s\n", request.Method)
fmt.Fprintf(writer, "Request Method: %q\n", request.URL)
package main
import ("fmt"
"net/http"
"log"
"io/ioutil"
"io"
"sync"
"os"
)
urls := [2]string{"https://vmware.com", "https://dell.com"}
var receive_channel string
send_channel := make(chan string)
var wg sync.WaitGroup
f, err := os.Create("/tmp/concurrency_in_go.txt")
if err != nil{
panic(err)
}
defer f.Close()
for i := 1; i <= 3; i++ {
wg.Add(1)
go worker(i, &wg, f)
}
for _, url := range urls {
go fetchUrl(url, send_channel)
}
for _, url := range urls {
fmt.Println("Fetching channel content for URL: ", url)
receive_channel = <-send_channel
fmt.Println(receive_channel)
}
func worker(pid int, wg *sync.WaitGroup, file *os.File){
defer wg.Done()
fmt.Printf("Worker Process %d writing to file...\n", pid)
content := fmt.Sprintf("Worker %d wrote to the file\n", pid)
file.WriteString(content)
file.Sync()
}
func fetchUrl(url string, send_channel chan<- string){
response, err := http.Get(url)
if(err != nil){
log.Fatal(err)
}
bytes, err := io.Copy(ioutil.Discard, response.Body)
response.Body.Close()
if(err != nil){
log.Fatal(err)
}
- kustomize.yaml
- networking
- networking-sync.yaml
- nginx-ingress-controller.yaml
- kustomize.yaml
- namespaces
- namespaces-sync.yaml
- ingress-controller-ns.yaml
- my-app-ns.yaml
- kustomize.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- app-system/app-system-sync.yaml
- networking/networking-sync.yaml
- namespaces/namespaces-sync.yaml
- app/app-sync.yaml
apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
kind: Kustomization
metadata:
name: app-sync
namespace: flux-system
spec:
interval: 10m
path: "./app"
sourceRef:
kind: GitRepository