package deal routes
import (
homeCtrl “aio-commerce/inner/modules/house/controllers”
“fmt”
“GitHub – gin-gonic/gin: Gin is a HTTP net framework written in Go (Golang). It includes a Martini-like API with a lot better efficiency — as much as 40 occasions sooner. For those who want smashing efficiency, get your self some Gin.”
“html/template”
“strconv”
)
func formatNumber(worth string) string {
s, err := strconv.Atoi(worth)
formatted := “”
if err == nil {
formatted = fmt.Sprintf(“%.0f”, s)
}
return formatted
}
func Routes(router *gin.Engine) {
homeController := homeCtrl.New()
router.SetFuncMap(template.FuncMap{
“formatNumber”: formatNumber,
})
router.GET(“/”, homeController.Index)
}
{{ .ShortNotes }}
{{ formatNumber .Value }}
Hello @amansu , welcome to the discussion board.
The textual content/template
documentation has a FuncMap instance, does this assist fixing your challenge?
If not, are you able to describe the precise drawback that you simply observe (error messages, anticipated habits versus noticed habits, and so forth.)?
A minimal however full code instance would even be useful. The code as given wouldn’t compile, and it doesn’t present how the template is executed. Ideally, the code instance ought to run within the playground.
Additionally a tip: to share code within the discussion board, use three backticks in a separate line initially and on the finish of the code, like so:
```go
// add go code right here
```
Optionally, add the phrase go
after the preliminary backticks, as proven.
The code will then be formatted with all indentation preserved, and with syntax highlighting utilized.
error is : template: house.tmpl:52: perform “formatNumber” not outlined
i’ve made the func
//func Routes(router *gin.Engine) {
// homeController := homeCtrl.New()
// router.SetFuncMap(template.FuncMap{
// "formatNumber": formatNumber,
// })
// router.GET("https://discussion board.golangbridge.org/", homeController.Index)
}