jager 3 years ago
parent e7ca929c4a
commit cdf8c0c1b5

@ -13,18 +13,16 @@
package api
import (
"github.com/gin-gonic/gin"
"github.com/jageros/hawox/jwt"
"idata/internal/service/almanac"
"idata/internal/service/dirty"
"idata/internal/service/network"
"idata/internal/service/soup"
"idata/internal/service/user"
"net/http"
"github.com/gin-gonic/gin"
)
func Registry(engine *gin.Engine) {
engine.GET("/my-ip", myIp)
r := engine.Group("/haw")
ur := r.Group("/user")
ur.POST("/register", user.Register)
@ -37,10 +35,7 @@ func Registry(engine *gin.Engine) {
apiR.GET("/soup", soup.GetRandSoup)
apiR.GET("/almanac", almanac.Almanac)
apiR.GET("/dirty_word", dirty.IsDirtyWord)
apiR.Static("/video", "./static/")
}
func myIp(ctx *gin.Context) {
addr := ctx.ClientIP()
ctx.String(http.StatusOK, addr)
apiR.GET("/my-ip", network.MyIp)
apiR.GET("/dns", network.Domain2IP)
apiR.GET("/domain", network.IP2Domain)
}

@ -22,6 +22,9 @@ const (
Obscenity // 3脏词检测
Almanac // 4黄历
Dirty // 5脏词检测
SelfIp // 6客户端自身ip
DomainIP // 7域名的ip
IPDomain // 8ip的域名
)
func Type(ty string) ApiType {

@ -19,7 +19,7 @@ import (
func TestApiType(t *testing.T) {
var opened int64 = 7
opened = opened & int64(Astro)
opened = opened & int64(Obscenity)
//opened = opened | int64(Obscenity)
//opened = opened | int64(Weather)
fmt.Printf("opened = %b\n", opened)

@ -13,6 +13,6 @@
package consts
const (
DateFormat = "2006-01-02"
DateFormat = "2006-01-02_15"
TimeFormat = "2006-01-02 15:04:05"
)

@ -29,8 +29,8 @@ func Almanac(ctx *gin.Context) {
if !user.Auth(ctx, apity.Almanac) {
return
}
date, ok := httpx.DecodeUrlVal(ctx, "date")
if !ok || date == "" {
date := ctx.Query("date")
if date == "" {
date = time.Now().Format(consts.DateFormat)
}
strs := strings.Split(date, "_")

@ -0,0 +1,63 @@
/**
* @Author: jager
* @Email: lhj168os@gmail.com
* @File: network
* @Date: 2022/2/7 5:35
* @package: network
* @Version: v1.0.0
*
* @Description:
*
*/
package network
import (
"github.com/gin-gonic/gin"
"github.com/jageros/hawox/errcode"
"github.com/jageros/hawox/httpx"
"idata/internal/apity"
"idata/internal/service/user"
"net"
"net/http"
)
func MyIp(ctx *gin.Context) {
if !user.Auth(ctx, apity.SelfIp) {
return
}
addr := ctx.ClientIP()
ctx.String(http.StatusOK, addr)
}
func Domain2IP(ctx *gin.Context) {
if !user.Auth(ctx, apity.DomainIP) {
return
}
domain, ok := httpx.DecodeUrlVal(ctx, "domain")
if !ok {
return
}
addrs, err := net.LookupHost(domain)
if err != nil {
httpx.ErrInterrupt(ctx, errcode.WithErrcode(1, err))
return
}
httpx.PkgMsgWrite(ctx, map[string]interface{}{"addrs": addrs})
}
func IP2Domain(ctx *gin.Context) {
if !user.Auth(ctx, apity.IPDomain) {
return
}
ip, ok := httpx.DecodeUrlVal(ctx, "ip")
if !ok {
return
}
names, err := net.LookupAddr(ip)
if err != nil {
httpx.ErrInterrupt(ctx, errcode.WithErrcode(1, err))
return
}
httpx.PkgMsgWrite(ctx, map[string]interface{}{"names": names})
}
Loading…
Cancel
Save