You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
605 B
Go
32 lines
605 B
Go
package api
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"io/ioutil"
|
|
"net/http"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
func GetTemplate(c *gin.Context) {
|
|
name := c.Param("name")
|
|
path := filepath.Join("template", name)
|
|
content, err := ioutil.ReadFile(path)
|
|
|
|
if err != nil {
|
|
if os.IsNotExist(err) {
|
|
c.JSON(http.StatusNotFound, gin.H{
|
|
"message": err.Error(),
|
|
})
|
|
return
|
|
}
|
|
ErrorHandler(c, err)
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"message": "ok",
|
|
"template": string(content),
|
|
})
|
|
}
|