jager 3 years ago
parent e7ca929c4a
commit cdf8c0c1b5

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

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

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

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

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