修复一些bug
This commit is contained in:
parent
f48005f796
commit
29cfee9d4e
|
@ -50,7 +50,7 @@ jobs:
|
||||||
if [ $GOOS = "windows" ]; then export BINARY_SUFFIX="$BINARY_SUFFIX.exe"; fi
|
if [ $GOOS = "windows" ]; then export BINARY_SUFFIX="$BINARY_SUFFIX.exe"; fi
|
||||||
if $IS_PR ; then echo $PR_PROMPT; fi
|
if $IS_PR ; then echo $PR_PROMPT; fi
|
||||||
export BINARY_NAME="$BINARY_PREFIX$GOOS_$GOARCH$BINARY_SUFFIX"
|
export BINARY_NAME="$BINARY_PREFIX$GOOS_$GOARCH$BINARY_SUFFIX"
|
||||||
export LD_FLAGS="-w -s -X github.com/huoxue1/qinglong-go/api/system.VERSION=$COMMIT_ID"
|
export LD_FLAGS="-w -s -X github.com/huoxue1/qinglong-go/service/config.VERSION=$COMMIT_ID"
|
||||||
go mod tidy
|
go mod tidy
|
||||||
go build -o "output/$BINARY_NAME" -trimpath -ldflags "$LD_FLAGS" ./
|
go build -o "output/$BINARY_NAME" -trimpath -ldflags "$LD_FLAGS" ./
|
||||||
- name: Upload artifact
|
- name: Upload artifact
|
||||||
|
|
|
@ -82,9 +82,8 @@ jobs:
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64,linux/386,linux/arm
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
cache-from: type=gha
|
cache-from: type=gha
|
||||||
cache-to: type=gha,mode=max
|
cache-to: type=gha,mode=max
|
||||||
shm-size: 2g
|
|
||||||
ulimit: core=0:0
|
ulimit: core=0:0
|
||||||
|
|
|
@ -30,7 +30,7 @@ builds:
|
||||||
flags:
|
flags:
|
||||||
- -trimpath
|
- -trimpath
|
||||||
ldflags:
|
ldflags:
|
||||||
- -s -w -X main.VERSION=v{{.Version}}
|
- -s -w -X github.com/huoxue1/qinglong-go/service/config.VERSION=v{{.Version}}
|
||||||
- id: win
|
- id: win
|
||||||
env:
|
env:
|
||||||
- CGO_ENABLED=0
|
- CGO_ENABLED=0
|
||||||
|
@ -46,7 +46,7 @@ builds:
|
||||||
flags:
|
flags:
|
||||||
- -trimpath
|
- -trimpath
|
||||||
ldflags:
|
ldflags:
|
||||||
- -s -w -X main.VERSION=v{{.Version}}
|
- -s -w -X github.com/huoxue1/qinglong-go/service/config.VERSION.VERSION=v{{.Version}}
|
||||||
- id: docker
|
- id: docker
|
||||||
env:
|
env:
|
||||||
- CGO_ENABLED=0
|
- CGO_ENABLED=0
|
||||||
|
@ -54,13 +54,17 @@ builds:
|
||||||
goos:
|
goos:
|
||||||
- linux
|
- linux
|
||||||
goarch:
|
goarch:
|
||||||
|
- 386
|
||||||
- amd64
|
- amd64
|
||||||
|
- arm
|
||||||
- arm64
|
- arm64
|
||||||
|
goarm:
|
||||||
|
- 7
|
||||||
mod_timestamp: "{{ .CommitTimestamp }}"
|
mod_timestamp: "{{ .CommitTimestamp }}"
|
||||||
flags:
|
flags:
|
||||||
- -trimpath
|
- -trimpath
|
||||||
ldflags:
|
ldflags:
|
||||||
- -s -w -X main.VERSION=v{{.Version}}
|
- -s -w -X github.com/huoxue1/qinglong-go/service/config.VERSION.VERSION=v{{.Version}}
|
||||||
|
|
||||||
checksum:
|
checksum:
|
||||||
name_template: "{{ .ProjectName }}_checksums.txt"
|
name_template: "{{ .ProjectName }}_checksums.txt"
|
||||||
|
|
|
@ -31,9 +31,6 @@ RUN set -x \
|
||||||
openssh \
|
openssh \
|
||||||
npm \
|
npm \
|
||||||
&& rm -rf /var/cache/apk/* \
|
&& rm -rf /var/cache/apk/* \
|
||||||
&& wget https://studygolang.com/dl/golang/go1.19.4.linux-${TARGETARCH}.tar.gz \
|
|
||||||
&& tar -C /usr/local -xzf go1.19.4.linux-${TARGETARCH}.tar.gz \
|
|
||||||
&& rm -rf go1.19.4.linux-${TARGETARCH}.tar.gz \
|
|
||||||
&& apk update \
|
&& apk update \
|
||||||
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
|
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
|
||||||
&& echo "Asia/Shanghai" > /etc/timezone \
|
&& echo "Asia/Shanghai" > /etc/timezone \
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"github.com/huoxue1/qinglong-go/api/env"
|
"github.com/huoxue1/qinglong-go/api/env"
|
||||||
"github.com/huoxue1/qinglong-go/api/logs"
|
"github.com/huoxue1/qinglong-go/api/logs"
|
||||||
"github.com/huoxue1/qinglong-go/api/open"
|
"github.com/huoxue1/qinglong-go/api/open"
|
||||||
|
"github.com/huoxue1/qinglong-go/api/public"
|
||||||
"github.com/huoxue1/qinglong-go/api/scripts"
|
"github.com/huoxue1/qinglong-go/api/scripts"
|
||||||
"github.com/huoxue1/qinglong-go/api/subscription"
|
"github.com/huoxue1/qinglong-go/api/subscription"
|
||||||
"github.com/huoxue1/qinglong-go/api/system"
|
"github.com/huoxue1/qinglong-go/api/system"
|
||||||
|
@ -27,4 +28,5 @@ func Api(group *gin.RouterGroup) {
|
||||||
logs.APi(group.Group("/logs"))
|
logs.APi(group.Group("/logs"))
|
||||||
dependencies.Api(group.Group("/dependencies"))
|
dependencies.Api(group.Group("/dependencies"))
|
||||||
ws.Api(group.Group("/ws"))
|
ws.Api(group.Group("/ws"))
|
||||||
|
public.Api(group.Group("/public"))
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,9 @@ func get() gin.HandlerFunc {
|
||||||
filters := ctx.QueryMap("queryString")["filters"]
|
filters := ctx.QueryMap("queryString")["filters"]
|
||||||
page, _ := strconv.Atoi(ctx.Query("page"))
|
page, _ := strconv.Atoi(ctx.Query("page"))
|
||||||
size, _ := strconv.Atoi(ctx.Query("size"))
|
size, _ := strconv.Atoi(ctx.Query("size"))
|
||||||
|
if size == 0 {
|
||||||
|
size = 1000
|
||||||
|
}
|
||||||
crons, err := cron.GetCrons(page, size, ctx.Query("searchValue"), sorter, filters)
|
crons, err := cron.GetCrons(page, size, ctx.Query("searchValue"), sorter, filters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(503, res.Err(503, err))
|
ctx.JSON(503, res.Err(503, err))
|
||||||
|
|
|
@ -19,6 +19,7 @@ var (
|
||||||
"/api/system",
|
"/api/system",
|
||||||
"/api/user/login",
|
"/api/user/login",
|
||||||
"/api/user/init",
|
"/api/user/init",
|
||||||
|
"api/public/panel/log",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package public
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"path"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Api(group *gin.RouterGroup) {
|
||||||
|
group.GET("/panel/log", log())
|
||||||
|
}
|
||||||
|
func log() gin.HandlerFunc {
|
||||||
|
return func(ctx *gin.Context) {
|
||||||
|
ctx.File(path.Join("data", "log", "qinglong-go", time.Now().Format("2006-01-02")+".log"))
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,6 +15,30 @@ func Api(group *gin.RouterGroup) {
|
||||||
group.POST("", post())
|
group.POST("", post())
|
||||||
group.DELETE("", del())
|
group.DELETE("", del())
|
||||||
group.GET("/:name", getFile())
|
group.GET("/:name", getFile())
|
||||||
|
|
||||||
|
group.PUT("/run", run())
|
||||||
|
}
|
||||||
|
|
||||||
|
func run() gin.HandlerFunc {
|
||||||
|
return func(ctx *gin.Context) {
|
||||||
|
type Req struct {
|
||||||
|
Path string `json:"path"`
|
||||||
|
FileName string `json:"filename"`
|
||||||
|
Content string `json:"content"`
|
||||||
|
}
|
||||||
|
r := new(Req)
|
||||||
|
err := ctx.ShouldBindJSON(r)
|
||||||
|
if err != nil {
|
||||||
|
ctx.JSON(503, res.Err(503, err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = scripts.Run(path2.Join(r.Path, "_"+r.FileName), r.Content)
|
||||||
|
if err != nil {
|
||||||
|
ctx.JSON(503, res.Err(503, err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ctx.JSON(200, res.Ok(true))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func get() gin.HandlerFunc {
|
func get() gin.HandlerFunc {
|
||||||
|
|
|
@ -2,16 +2,13 @@ package system
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/huoxue1/qinglong-go/service/config"
|
||||||
"github.com/huoxue1/qinglong-go/service/system"
|
"github.com/huoxue1/qinglong-go/service/system"
|
||||||
"github.com/huoxue1/qinglong-go/utils/res"
|
"github.com/huoxue1/qinglong-go/utils/res"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
VERSION = "UNKNOWN"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Api(group *gin.RouterGroup) {
|
func Api(group *gin.RouterGroup) {
|
||||||
group.GET("", get())
|
group.GET("", get())
|
||||||
}
|
}
|
||||||
|
@ -22,10 +19,10 @@ func get() gin.HandlerFunc {
|
||||||
exist := os.IsNotExist(err)
|
exist := os.IsNotExist(err)
|
||||||
ctx.JSON(200, res.Ok(system.System{
|
ctx.JSON(200, res.Ok(system.System{
|
||||||
IsInitialized: !exist,
|
IsInitialized: !exist,
|
||||||
Version: VERSION,
|
Version: config.GetVersion(),
|
||||||
LastCommitTime: "",
|
LastCommitTime: "",
|
||||||
LastCommitId: "",
|
LastCommitId: "",
|
||||||
Branch: "master",
|
Branch: "Main",
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,6 +111,11 @@ func login() gin.HandlerFunc {
|
||||||
ctx.JSON(503, res.Err(503, err))
|
ctx.JSON(503, res.Err(503, err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
ip, err := user.GetNetIp(ctx.RemoteIP())
|
||||||
|
if err != nil {
|
||||||
|
ip = new(user.Ip)
|
||||||
|
err = nil
|
||||||
|
}
|
||||||
mobile := utils.IsMobile(ctx.GetHeader("User-Agent"))
|
mobile := utils.IsMobile(ctx.GetHeader("User-Agent"))
|
||||||
if mobile {
|
if mobile {
|
||||||
auth.Tokens.Mobile = token
|
auth.Tokens.Mobile = token
|
||||||
|
@ -126,8 +131,8 @@ func login() gin.HandlerFunc {
|
||||||
"token": token,
|
"token": token,
|
||||||
"platform": "mobile",
|
"platform": "mobile",
|
||||||
"retries": 0,
|
"retries": 0,
|
||||||
"lastip": "",
|
"lastip": ctx.RemoteIP(),
|
||||||
"lastaddr": "",
|
"lastaddr": ip.Addr,
|
||||||
"lastlogon": time.Now().UnixNano(),
|
"lastlogon": time.Now().UnixNano(),
|
||||||
}))
|
}))
|
||||||
} else {
|
} else {
|
||||||
|
@ -144,9 +149,9 @@ func login() gin.HandlerFunc {
|
||||||
"token": token,
|
"token": token,
|
||||||
"platform": "desktop",
|
"platform": "desktop",
|
||||||
"retries": 0,
|
"retries": 0,
|
||||||
"lastip": "",
|
"lastip": ctx.RemoteIP(),
|
||||||
"lastaddr": "",
|
"lastaddr": ip.Addr,
|
||||||
"lastlogon": time.Now().UnixNano(),
|
"lastlogon": time.Now().Unix(),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -3,7 +3,7 @@ package ws
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/gobwas/ws"
|
"github.com/gobwas/ws"
|
||||||
"github.com/gobwas/ws/wsutil"
|
"github.com/huoxue1/qinglong-go/service/client"
|
||||||
"github.com/huoxue1/qinglong-go/utils/res"
|
"github.com/huoxue1/qinglong-go/utils/res"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -25,8 +25,7 @@ func wsHandle() gin.HandlerFunc {
|
||||||
ctx.JSON(502, res.Err(502, err))
|
ctx.JSON(502, res.Err(502, err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
writer := wsutil.NewWriter(conn, ws.StateServerSide, ws.OpText)
|
|
||||||
writer.Write([]byte("pong"))
|
client.AddWs(ctx.Param("id")+"_"+ctx.Param("name"), conn)
|
||||||
writer.Flush()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
2
main.go
2
main.go
|
@ -39,5 +39,5 @@ func init() {
|
||||||
func main() {
|
func main() {
|
||||||
service.AppInit()
|
service.AppInit()
|
||||||
engine := controller.Router()
|
engine := controller.Router()
|
||||||
_ = engine.Run(":8080")
|
_ = engine.Run(":5700")
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
package client
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/gobwas/ws"
|
||||||
|
"github.com/gobwas/ws/wsutil"
|
||||||
|
"net"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Clients struct {
|
||||||
|
sync.Map
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Clients) Write(p []byte) (n int, err error) {
|
||||||
|
data := map[string]string{"type": "manuallyRunScript", "message": string(p)}
|
||||||
|
content, _ := json.Marshal(data)
|
||||||
|
var deleSlince []string
|
||||||
|
c.Range(func(key, value any) bool {
|
||||||
|
conn := value.(*Client).conn
|
||||||
|
writer := wsutil.NewWriter(conn, ws.StateServerSide, ws.OpText)
|
||||||
|
_, err := writer.Write(content)
|
||||||
|
if err != nil {
|
||||||
|
deleSlince = append(deleSlince, key.(string))
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
err = writer.Flush()
|
||||||
|
if err != nil {
|
||||||
|
deleSlince = append(deleSlince, key.(string))
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
for _, s := range deleSlince {
|
||||||
|
c.Delete(s)
|
||||||
|
}
|
||||||
|
return len(p), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
MyClient *Clients
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
MyClient = new(Clients)
|
||||||
|
}
|
||||||
|
|
||||||
|
type Client struct {
|
||||||
|
conn net.Conn
|
||||||
|
}
|
||||||
|
|
||||||
|
func AddWs(id string, conn net.Conn) {
|
||||||
|
MyClient.Store(id, &Client{
|
||||||
|
conn: conn,
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
|
@ -6,6 +6,8 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var VERSION = "test"
|
||||||
|
|
||||||
func GetKey(key string) string {
|
func GetKey(key string) string {
|
||||||
file, err := os.ReadFile(path.Join("data", "config", "config.sh"))
|
file, err := os.ReadFile(path.Join("data", "config", "config.sh"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -18,3 +20,7 @@ func GetKey(key string) string {
|
||||||
datas := compile.FindAllStringSubmatch(string(file), 1)
|
datas := compile.FindAllStringSubmatch(string(file), 1)
|
||||||
return datas[0][1]
|
return datas[0][1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetVersion() string {
|
||||||
|
return VERSION
|
||||||
|
}
|
||||||
|
|
|
@ -20,7 +20,9 @@ func DeleteCron(ids []int) error {
|
||||||
for _, id := range ids {
|
for _, id := range ids {
|
||||||
|
|
||||||
c, _ := manager.Load(id)
|
c, _ := manager.Load(id)
|
||||||
|
if c != nil {
|
||||||
c.(*cron.Cron).Stop()
|
c.(*cron.Cron).Stop()
|
||||||
|
}
|
||||||
|
|
||||||
err := models.DeleteCron(id)
|
err := models.DeleteCron(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -16,6 +16,8 @@ func AddDep(dep *models.Dependences) {
|
||||||
addNodeDep(dep)
|
addNodeDep(dep)
|
||||||
} else if dep.Type == models.PYTHON {
|
} else if dep.Type == models.PYTHON {
|
||||||
addPythonDep(dep)
|
addPythonDep(dep)
|
||||||
|
} else {
|
||||||
|
addLinuxDep(dep)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,3 +62,24 @@ func addPythonDep(dep *models.Dependences) {
|
||||||
models.AddDependences(dep)
|
models.AddDependences(dep)
|
||||||
}, buffer)
|
}, buffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func addLinuxDep(dep *models.Dependences) {
|
||||||
|
log := ""
|
||||||
|
buffer := bytes.NewBufferString(log)
|
||||||
|
ctx := context.WithValue(context.Background(), "cancel", make(chan int, 1))
|
||||||
|
now := time.Now()
|
||||||
|
utils.RunTask(ctx, fmt.Sprintf("apk add %s", dep.Name), map[string]string{}, func(ctx context.Context) {
|
||||||
|
writer := ctx.Value("log").(io.Writer)
|
||||||
|
writer.Write([]byte(fmt.Sprintf("##开始执行.. %s\n\n", now.Format("2006-01-02 15:04:05"))))
|
||||||
|
}, func(ctx context.Context) {
|
||||||
|
writer := ctx.Value("log").(io.Writer)
|
||||||
|
writer.Write([]byte(fmt.Sprintf("\n##执行结束.. %s,耗时%.1f秒\n\n", time.Now().Format("2006-01-02 15:04:05"), time.Now().Sub(now).Seconds())))
|
||||||
|
dep.Status = 1
|
||||||
|
var logs []string
|
||||||
|
for _, i2 := range strings.Split(buffer.String(), "\n") {
|
||||||
|
logs = append(logs, i2+"\n\n")
|
||||||
|
}
|
||||||
|
dep.Log = logs
|
||||||
|
models.AddDependences(dep)
|
||||||
|
}, buffer)
|
||||||
|
}
|
||||||
|
|
|
@ -109,3 +109,16 @@ func LoadEnvFromFile(file string) map[string]string {
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetALlEnv() map[string]string {
|
||||||
|
envFromDb := LoadEnvFromDb()
|
||||||
|
envfromFile := LoadEnvFromFile("data/config/config.sh")
|
||||||
|
for s, s2 := range envfromFile {
|
||||||
|
if _, ok := envFromDb[s]; ok {
|
||||||
|
envFromDb[s] = envFromDb[s] + "&" + s2
|
||||||
|
} else {
|
||||||
|
envFromDb[s] = s2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return envFromDb
|
||||||
|
}
|
||||||
|
|
|
@ -2,10 +2,18 @@ package scripts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"github.com/huoxue1/qinglong-go/service/client"
|
||||||
|
"github.com/huoxue1/qinglong-go/service/env"
|
||||||
"github.com/huoxue1/qinglong-go/utils"
|
"github.com/huoxue1/qinglong-go/utils"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type File struct {
|
type File struct {
|
||||||
|
@ -24,6 +32,38 @@ var (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func Run(filePath, content string) error {
|
||||||
|
err := os.WriteFile(path.Join("data", "scripts", filePath), []byte(content), 0666)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
cmd := getCmd(filePath)
|
||||||
|
cancelChan := make(chan int, 1)
|
||||||
|
ctx := context.WithValue(context.Background(), "cancel", cancelChan)
|
||||||
|
now := time.Now()
|
||||||
|
utils.RunTask(ctx, cmd, env.GetALlEnv(), func(ctx context.Context) {
|
||||||
|
writer := ctx.Value("log").(io.Writer)
|
||||||
|
_, _ = writer.Write([]byte(fmt.Sprintf("##开始执行.. %s\n\n", now.Format("2006-01-02 15:04:05"))))
|
||||||
|
}, func(ctx context.Context) {
|
||||||
|
writer := ctx.Value("log").(io.Writer)
|
||||||
|
_, _ = writer.Write([]byte(fmt.Sprintf("\n##执行结束.. %s,耗时%.1f秒\n\n", time.Now().Format("2006-01-02 15:04:05"), time.Now().Sub(now).Seconds())))
|
||||||
|
_ = os.Remove(filePath)
|
||||||
|
}, client.MyClient)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getCmd(filePath string) string {
|
||||||
|
ext := filepath.Ext(filePath)
|
||||||
|
switch ext {
|
||||||
|
case ".js":
|
||||||
|
return fmt.Sprintf("%s %s", "node", filePath)
|
||||||
|
case ".py":
|
||||||
|
return fmt.Sprintf("%s %s", "python", filePath)
|
||||||
|
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func GetFiles(base, p string) []*File {
|
func GetFiles(base, p string) []*File {
|
||||||
var files Files
|
var files Files
|
||||||
dir, err := os.ReadDir(path.Join(base, p))
|
dir, err := os.ReadDir(path.Join(base, p))
|
||||||
|
@ -46,6 +86,9 @@ func GetFiles(base, p string) []*File {
|
||||||
files = append(files, f)
|
files = append(files, f)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
if strings.HasPrefix(entry.Name(), "_") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
files = append(files, &File{
|
files = append(files, &File{
|
||||||
Key: path.Join(p, entry.Name()),
|
Key: path.Join(p, entry.Name()),
|
||||||
Parent: p,
|
Parent: p,
|
||||||
|
|
|
@ -2,6 +2,7 @@ package user
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"github.com/huoxue1/qinglong-go/utils"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -31,3 +32,25 @@ func GetUserInfo() (*Info, error) {
|
||||||
return i, err
|
return i, err
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Ip struct {
|
||||||
|
Ip string `json:"ip"`
|
||||||
|
Pro string `json:"pro"`
|
||||||
|
ProCode string `json:"proCode"`
|
||||||
|
City string `json:"city"`
|
||||||
|
CityCode string `json:"cityCode"`
|
||||||
|
Region string `json:"region"`
|
||||||
|
RegionCode string `json:"regionCode"`
|
||||||
|
Addr string `json:"addr"`
|
||||||
|
RegionNames string `json:"regionNames"`
|
||||||
|
Err string `json:"err"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetNetIp(ip string) (*Ip, error) {
|
||||||
|
i := new(Ip)
|
||||||
|
_, err := utils.GetClient().R().SetQueryParams(map[string]string{"ip": ip, "json": "true"}).SetResult(i).Get("https://whois.pconline.com.cn/ipJson.jsp")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return i, nil
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/imroc/req/v3"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
client *req.Client
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
client = req.C().SetProxy(http.ProxyFromEnvironment)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetClient() *req.Client {
|
||||||
|
return client
|
||||||
|
}
|
Loading…
Reference in New Issue