package main

import (
	"github.com/gin-gonic/gin"
)

func IPWhiteListMiddleware() gin.HandlerFunc {
	return func(c *gin.Context) {
		ipList := []string{
			"127.0.0.1",
		}
		flag := false
		clientIp := c.ClientIP()
		for _, host := range ipList {
			if clientIp == host {
				flag = true
			}
		}
		if !flag {
			c.String(401, "%s, 不在白名单中拒绝访问 \n", clientIp)
			c.Abort()
		}
	}
}

func GetRouter() *gin.Engine {
	router := gin.Default()
	//router.Use(IPWhiteListMiddleware())
	router.POST("/user/getBalance/:agentName", GetBalance)
	router.POST("/account/transfer/:agentName", Transfer)
	router.POST("/account/checkTransfer/:agentName", CheckTransfer)
	router.POST("/account/inform/:agentName", Inform)
	router.POST("/account/order/:agentName", Order)
	router.POST("/account/unsettle/:agentName", Unsettle)
	return router
}
