template.go 804 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package api
  2. import (
  3. "github.com/0xJacky/Nginx-UI/settings"
  4. "github.com/gin-gonic/gin"
  5. "io/ioutil"
  6. "net/http"
  7. "os"
  8. "path/filepath"
  9. "strings"
  10. )
  11. func GetTemplate(c *gin.Context) {
  12. name := c.Param("name")
  13. path := filepath.Join("template", name)
  14. content, err := ioutil.ReadFile(path)
  15. _content := string(content)
  16. _content = strings.ReplaceAll(_content, "{{ HTTP01PORT }}",
  17. settings.ServerSettings.HTTPChallengePort)
  18. if err != nil {
  19. if os.IsNotExist(err) {
  20. c.JSON(http.StatusNotFound, gin.H{
  21. "message": err.Error(),
  22. })
  23. return
  24. }
  25. ErrorHandler(c, err)
  26. return
  27. }
  28. c.JSON(http.StatusOK, gin.H{
  29. "message": "ok",
  30. "template": _content,
  31. })
  32. }