---
# System prepended metadata

title: Untitled

---

```
func getWallethandler() http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {

		if pusher, ok := w.(http.Pusher); ok {
			options := &http.PushOptions{}
			if err := pusher.Push("/account/user", options); err != nil {
				log.Printf("Failed to push: %v", err)
			}
			if err := pusher.Push("/wallet/balance", options); err != nil {
				log.Printf("Failed to push: %v", err)
			}
			if err := pusher.Push("/wallet/history", options); err != nil {
				log.Printf("Failed to push: %v", err)
			}
			if err := pusher.Push("/wallet/deposit", options); err != nil {
				log.Printf("Failed to push: %v", err)
			}
			if err := pusher.Push("/wallet/rate", nil); err != nil {
				log.Printf("Failed to push: %v", err)
			}

			services.JSONResponse(w, http.StatusOK, &services.Response{Success: true, Message: "Push supported", Data: nil})
			return
		}

		services.JSONResponse(w, http.StatusOK, &services.Response{Success: false, Message: "Push not supported", Data: nil})
	}
}

func getWalletUpdatehandler() http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {

		if _, ok := w.(http.Flusher); ok {

			w.Header().Set("Content-Type", "text/event-stream")
			w.Header().Set("Cache-Control", "no-cache")
			w.Header().Set("Connection", "keep-alive")
			w.Header().Set("Access-Control-Allow-Origin", "*")
			writeRate(w, r)

			services.JSONResponse(w, http.StatusOK, &services.Response{Success: true, Message: "Push supported", Data: nil})
			return
		}

		services.JSONResponse(w, http.StatusBadRequest, &services.Response{Success: false, Message: "Push not supported", Data: nil})
	}
}

type flushWriter struct {
	w io.Writer
}

func (fw flushWriter) Write(p []byte) (n int, err error) {
	n, err = fw.w.Write(p)
	if f, ok := fw.w.(http.Flusher); ok {
		f.Flush()
	}
	return
}

func writeRate(w http.ResponseWriter, r *http.Request) {
	f := flushWriter{w: w}
	c2 := make(chan interface{})
	res := services.GetRateReq{}
	n := 0
	go func() {
		for range time.Tick(time.Second * 5) {
			_, _, rates, _ := res.Controller()
			c2 <- rates
		}

	}()
	for {
		select {
		case rate := <-c2:
			fmt.Println("writing ", n)
			out, _ := json.Marshal(rate)
			f.Write([]byte(fmt.Sprintf("data: %s\n\n", string(out))))
		case <-r.Context().Done():
			fmt.Println("Breaking")
			return
		}
		n++
	}
}
```