add private api
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package private
|
||||
|
||||
import (
|
||||
pubmodel "dorisbot/models/public"
|
||||
"dorisbot/pkg/config"
|
||||
"dorisbot/pkg/context"
|
||||
"net/http"
|
||||
"net/textproto"
|
||||
)
|
||||
|
||||
// VerifyKey -
|
||||
func VerifyKey(c *context.Context) {
|
||||
conf := config.GetConfig()
|
||||
key := c.GetHeader(textproto.CanonicalMIMEHeaderKey("x-mtfos-key"))
|
||||
|
||||
if len(key) == 0 || key != conf.SelfKey {
|
||||
c.CustomRes(http.StatusForbidden, map[string]string{
|
||||
"message": "key empty or not match",
|
||||
})
|
||||
return
|
||||
}
|
||||
c.Next()
|
||||
}
|
||||
|
||||
// GetFacebookIDs -
|
||||
func GetFacebookIDs(c *context.Context) {
|
||||
pages, err := pubmodel.GetAllFacebookPage()
|
||||
if err != nil {
|
||||
c.ServerError()
|
||||
return
|
||||
}
|
||||
|
||||
ids := make([]string, 0, len(pages))
|
||||
for _, v := range pages {
|
||||
ids = append(ids, v.ID)
|
||||
}
|
||||
|
||||
c.Success(map[string]interface{}{"list": ids})
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"dorisbot/pkg/context"
|
||||
"net/http"
|
||||
|
||||
"dorisbot/route/private"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// NewEngine -
|
||||
func NewEngine() *gin.Engine {
|
||||
e := gin.New()
|
||||
e.Use(gin.Recovery())
|
||||
e.Use(gin.Logger())
|
||||
return e
|
||||
}
|
||||
|
||||
// SetRoutes -
|
||||
func SetRoutes(e *gin.Engine) {
|
||||
e.GET("/", func(c *gin.Context) {
|
||||
c.String(http.StatusOK, "ok")
|
||||
})
|
||||
|
||||
privGroup := e.Group("/private")
|
||||
{
|
||||
privGroup.GET("/pages", context.PatchCtx(private.VerifyKey), context.PatchCtx(private.GetFacebookIDs))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user