Files
iptv-tools/core/gin_handler.go
2024-08-02 14:19:57 +08:00

44 lines
1.1 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package core
import (
"fmt"
"github.com/gin-gonic/gin"
)
func HandlerIpv6M3u(c *gin.Context) {
filename := "./ipv6.m3u"
// 检查缓存文件是否存在
if exists := IsFileExist(filename); !exists {
c.JSON(200, gin.H{"code": -1, "msg": "缓存文件不存在"})
return
}
content, err := ReadFile(filename)
if err != nil {
fmt.Printf("读取缓存文件ipv6.m3u失败%s\n", err.Error())
c.JSON(200, gin.H{"code": -1, "msg": "读取缓存文件失败"})
return
}
// 返回响应内容
c.Header("Content-Type", "text/plain; charset=utf-8")
c.String(200, content)
}
func HandlerDiypIpv6IptvM3u(c *gin.Context) {
filename := "./ipv6-txt.m3u"
// 检查缓存文件是否存在
if exists := IsFileExist(filename); !exists {
c.JSON(200, gin.H{"code": -1, "msg": "缓存文件不存在"})
return
}
content, err := ReadFile(filename)
if err != nil {
fmt.Printf("读取缓存文件ipv6-txt.m3u失败%s\n", err.Error())
c.JSON(200, gin.H{"code": -1, "msg": "读取缓存文件失败"})
return
}
// 返回响应内容
c.Header("Content-Type", "text/plain; charset=utf-8")
c.String(200, content)
}