Need help with template

Hi I have the following function, which basically need to show a list of orders placed. The results is coming from aerospike set which any way i am not able to send to template because all the interface{} to []interface{} to string issue in the bins so i get value of bin the below code and make a map and then send map to the template. Now the value is in the format of [XXX] = {[test],[test1],[test2]} .

Now how do we get the right side that to loop so i can make

s proroperly

This the function

func orderlist(w http.ResponseWriter, r *http.Request) {
fmt.Println(“method:”, r.Method) //get request method
if r.Method == “GET” {
stmt := as.NewStatement(“trade”,“orders”,“tradingsymbol”,“exchange”,“segment”,“instrumenttype”,“buysell”,“appstatus”,“ordertype”,“product”,“validity”,“qty”)
rsorderlist, err = asclient.Query(nil,stmt)
if err != nil {
fmt.Println(“error:”, err)
}

    var tradingsymbol string
    var exchange string
    var instrumenttype string
    var buysell string
    var appstatus string
    var ordertype string
    var product string
    var validity string
    //var qty int
    var rowstr string
    type orderdetails struct {
        tradingsymbol string
        exchange string
        segment string
        instrumenttype string
        buysell string
        appstatus string
        ordertype string
        product string
        validity string
    }

    var m map[string]orderdetails
    m = make(map[string]orderdetails)
    w.Header().Set("Content-Type", "text/html")
    
            for rec := range rsorderlist.Records {
                
                for mybin, val := range rec.Bins {
                    

                switch mybin {
                    case "tradingsymbol":
                        tradingsymbol = fmt.Sprintf("%v", val)
                    case "exchange":
                        exchange = fmt.Sprintf("%v", val)
                    case "segment":
                        segment = fmt.Sprintf("%v", val)
                    case "instrumenttype":
                        instrumenttype = fmt.Sprintf("%v", val)
                    case "buysell":
                        buysell = fmt.Sprintf("%v", val)
                    case "appstatus":
                        appstatus = fmt.Sprintf("%v", val)
                    case "ordertype":
                        ordertype = fmt.Sprintf("%v", val)
                    case "product":
                        product = fmt.Sprintf("%v", val)
                    case "validity":
                        validity = fmt.Sprintf("%v", val)
                    //case "qty":
                        //qty = val.(int)
                    }

                    m[tradingsymbol] = orderdetails{tradingsymbol,exchange,segment,instrumenttype,buysell,appstatus,ordertype,product,validity}

                }
            }

    display(w, "orderlist", &m)
}

And the below is the template which is working
{{define “orderlist”}}
{{template “header” }}

<div class="container-fluid">

{{ range $key, $value := . }}



{{ $key }}


{{ $value }}


{{ end }}
</div>

{{template “footer” .}}
{{end}}

But i need further sub divide for columns so the template that is not working is

{{define “orderlist”}}
{{template “header” }}

<div class="container-fluid">

{{ range $key, $value := . }}
{{range $val := $value }}



{{ $key }}


{{ $val }}


{{ end }}
{{ end }}
</div>

{{template “footer” .}}
{{end}}

The best would be to get the aerospace records to template but that was not easy or may not be possible so i am find with for loop in the function and send resulting map.

Could you please format the code.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.