Skip to content

Hero Template ExampleΒ #31

@borowiak

Description

@borowiak

Hi everyone, I wrote code for Hero template system example and
I merged it with Gin framework, i didn't see any like this in documentation, I think this can be useful for someone else.
I based my code en 2 basic examples.
I don't sure where post this, so I opened a issues
please feel free to write any suggestion.

@shiyanhui/hero

`package main

import (
"bytes"
"fmt"
"ginapp/template"
"io"
"net/http"

"github.com/gin-gonic/gin"

)

func main() {
router := gin.Default()
router.GET("/someDataFromReader", func(c *gin.Context) {
var buffer bytes.Buffer
var reader io.Reader
contentType := "text/html , utf8"

	extraHeaders := map[string]string{
		"accept-ranges": "bytes",
	}
    
	var userList = []string{
		"Alice",
		"Bob",
		"Tom",
	}

	template.UserList(userList, &buffer)

	nRead := int64(len(buffer.Bytes()))
	reader = bytes.NewReader(buffer.Bytes())

	fmt.Println(nRead)

	c.DataFromReader(http.StatusOK, nRead, contentType, reader, extraHeaders)
})
router.Run(":8080")

}
`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions