package api import ( "fmt" "github.com/gin-gonic/gin" "html/template" "payment-poc/domain/state" ) func LoadTemplates(server *gin.Engine) { server.SetFuncMap(template.FuncMap{ "formatCurrency": formatCurrency, "formatCurrencyPtr": formatCurrencyPtr, "decimalCurrency": decimalCurrency, "formatState": formatState, "omitempty": omitempty, }) server.LoadHTMLGlob("./templates/*.gohtml") } func formatState(stt state.PaymentState) string { switch stt { case state.StateCanceled: return "Otkazana" case state.StateVoided: return "Poništena" case state.StateAccepted: return "Predautorizirana" case state.StateError: return "Greška" case state.StatePreinitialized: return "Predinicijalizirana" case state.StateInitialized: return "Inicijalizirana" case state.StateCanceledInitialization: return "Otkazana tijekom izrade" case state.StateCompleted: return "Autorizirana" } return "nepoznato stanje '" + string(stt) + "'" } func formatCurrency(current int64) string { return fmt.Sprintf("%d,%02d", current/100, current%100) } func formatCurrencyPtr(current *int64) string { if current != nil { return fmt.Sprintf("%d,%02d", (*current)/100, (*current)%100) } else { return "-" } } func decimalCurrency(current int64) string { return fmt.Sprintf("%d,%02d", current/100, current%100) } func omitempty(value string) string { if value == "" { return "-" } return value }