12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- package template
- import (
- "github.com/0xJacky/Nginx-UI/api"
- "github.com/0xJacky/Nginx-UI/internal/nginx"
- "github.com/0xJacky/Nginx-UI/internal/template"
- "github.com/gin-gonic/gin"
- "net/http"
- )
- func GetTemplate(c *gin.Context) {
- var ngxConfig *nginx.NgxConfig
- ngxConfig = &nginx.NgxConfig{
- Servers: []*nginx.NgxServer{
- {
- Directives: []*nginx.NgxDirective{
- {
- Directive: "listen",
- Params: "80",
- },
- {
- Directive: "listen",
- Params: "[::]:80",
- },
- {
- Directive: "server_name",
- },
- {
- Directive: "root",
- },
- {
- Directive: "index",
- },
- },
- Locations: []*nginx.NgxLocation{},
- },
- },
- }
- c.JSON(http.StatusOK, gin.H{
- "message": "ok",
- "template": ngxConfig.BuildConfig(),
- "tokenized": ngxConfig,
- })
- }
- func GetTemplateConfList(c *gin.Context) {
- configList, err := template.GetTemplateList("conf")
- if err != nil {
- api.ErrHandler(c, err)
- return
- }
- c.JSON(http.StatusOK, gin.H{
- "data": configList,
- })
- }
- func GetTemplateBlockList(c *gin.Context) {
- configList, err := template.GetTemplateList("block")
- if err != nil {
- api.ErrHandler(c, err)
- return
- }
- c.JSON(http.StatusOK, gin.H{
- "data": configList,
- })
- }
- func GetTemplateBlock(c *gin.Context) {
- type resp struct {
- template.ConfigInfoItem
- template.ConfigDetail
- }
- var bindData map[string]template.Variable
- _ = c.ShouldBindJSON(&bindData)
- info := template.GetTemplateInfo("block", c.Param("name"))
- if bindData == nil {
- bindData = info.Variables
- }
- detail, err := template.ParseTemplate("block", c.Param("name"), bindData)
- if err != nil {
- api.ErrHandler(c, err)
- return
- }
- info.Variables = bindData
- c.JSON(http.StatusOK, resp{
- info,
- detail,
- })
- }
|