Skip to content

Commit

Permalink
dev: add util.RunCmdWithTimeoutCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
peacewang017 authored and ActivePeter committed Jan 16, 2025
1 parent bf5e0bd commit d1eab39
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 96 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Check TeleYard

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: "1.22" # 设置 Go 版本为 1.22

- name: Install dependencies
run: |
go mod tidy # 更新并安装所有依赖
- name: Run tests
run: |
go test ./... -v # 运行所有测试
53 changes: 0 additions & 53 deletions app/job_filepath_server.go

This file was deleted.

53 changes: 53 additions & 0 deletions app/job_get_all_user_storage_link_server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package app

// 本模块为一个

import (
"fmt"

"github.com/gin-gonic/gin"
"github.com/spf13/cobra"
)

type ModJobGetAllUserStorageLinkServerStruct struct{}

var ModJobGetAllUserStorageLinkServer ModJobGetAllUserStorageLinkServerStruct

func (m ModJobGetAllUserStorageLinkServerStruct) JobCmdName() string {
return "get-all-user-storage-server"
}

func (m ModJobGetAllUserStorageLinkServerStruct) handleGetPath(c *gin.Context) {
userName := c.DefaultQuery("username", "")
if userName == "" {
c.JSON(400, gin.H{
"error": "username is required",
})
return
}

// 处理

// 未完成
c.JSON(200, GetAllUserStorageLinkResponse{
RemoteLinks: []string{"path1", "path2", "path3"},
})
}

func (m ModJobGetAllUserStorageLinkServerStruct) listenRequest(port int) {
r := gin.Default()
r.GET("/getalluserstoragelink", m.handleGetPath)
r.Run(fmt.Sprintf(":%d", port))
}

func (m ModJobGetAllUserStorageLinkServerStruct) Run() {
go m.listenRequest(8083)
}

func (m ModJobGetAllUserStorageLinkServerStruct) ParseJob(getAllUserStorageLinkServerCmd *cobra.Command) *cobra.Command {
getAllUserStorageLinkServerCmd.Run = func(_ *cobra.Command, _ []string) {
m.Run()
}

return getAllUserStorageLinkServerCmd
}
39 changes: 8 additions & 31 deletions app/job_mount_all_user_storage.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package app

import (
"fmt"
"os"
"telego/util"

"github.com/fatih/color"
"github.com/spf13/cobra"
)

Expand All @@ -17,37 +12,20 @@ func (m ModJobMountAllUserStorageStruct) JobCmdName() string {
return "mount-all-user-storage"
}

type PathRequest struct {
UserName string
PassWord string
// 请求结构体
type GetAllUserStorageLinkRequest struct {
UserName string `json:"username"` // Telego 用户名
}

type PathResponse struct {
RemotePaths []string `json: "remote_paths"`
// 返回结构体
type GetAllUserStorageLinkResponse struct {
RemoteLinks []string `json:"remote_links"` // 供 SshFs 进行挂载的远程链接
}

func (m ModJobMountAllUserStorageStruct) Run() {
ok, userName := util.StartTemporaryInputUI(
color.GreenString("Mount 用户存储空间需要鉴权,userName"),
"输入 userName",
"回车确认,ctrl + c 取消",
)
if !ok {
fmt.Println("User caceled input")
os.Exit(1)
}
// 填入 GetAllUserStorageLinkRequest

ok, passWord := util.StartTemporaryInputUI(
color.GreenString("Mount 用户存储空间需要鉴权,passWord"),
"输入 passWord",
"回车确认,ctrl + c 取消",
)
if !ok {
fmt.Println("User caceled input")
os.Exit(1)
}

// 进行 http 请求 server
// 进行 http Get 请求

// 接收结果,调用 ssh / rclone 进行挂载
}
Expand All @@ -56,6 +34,5 @@ func (m ModJobMountAllUserStorageStruct) ParseJob(mountAllUserStorageCmd *cobra.
mountAllUserStorageCmd.Run = func(_ *cobra.Command, _ []string) {
m.Run()
}

return mountAllUserStorageCmd
}
2 changes: 1 addition & 1 deletion app/joblist.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ var jobmods = []JobModInterface{
ModJobApplyDist,
ModJobInfraExporterSingle,
ModJobMountAllUserStorage,
ModJobFilePathServer,
ModJobGetAllUserStorageLinkServer,
}
9 changes: 0 additions & 9 deletions app/menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,6 @@ var MenuTreeData = `children:
name: install
comment: "\u6A21\u677F\u9879\u76EE"
name: bin_rclone
- children:
- children: []
comment: "\u6839\u636E\u6A21\u677F\u751F\u6210\u9879\u76EE"
name: generate
- children: []
comment: "\u76F4\u63A5\u5B89\u88C5\u8BE5\u9879\u76EE"
name: install
comment: "\u6A21\u677F\u9879\u76EE"
name: bin_winfsp
- children:
- children: []
comment: "\u6839\u636E\u6A21\u677F\u751F\u6210\u9879\u76EE"
Expand Down
8 changes: 6 additions & 2 deletions util/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ func LogDir() string {
logDir := filepath.Join(WorkspaceDir(), "logs")
if !createdLogDir {
PrintStep("log", "create log dir")
os.MkdirAll(logDir, 0755)
err := os.MkdirAll(logDir, 0755)
if err != nil || func() bool { _, err = os.Stat(logDir); return err != nil }() {
fmt.Println("LogDir: MkdirAll error")
os.Exit(1)
}
createdLogDir = true
}
return logDir
Expand All @@ -35,7 +39,7 @@ func SetupFileLog() *os.File {
Logger.SetLevel(logrus.DebugLevel)
// time stamp
curtime := time.Now().Format("2006-01-02-15h04m05s")
file, err := os.OpenFile(path.Join(LogDir(), fmt.Sprintf("%s.log", curtime)), os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0666)
file, err := os.OpenFile(path.Join(LogDir(), fmt.Sprintf("%s.log", curtime)), os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0755)
if err != nil {
fmt.Printf("Error opening log file: %v\n", err)
return nil
Expand Down
4 changes: 4 additions & 0 deletions util/storage_interface/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package storage_interface

type UserStorageInfoGetter interface {
}

0 comments on commit d1eab39

Please sign in to comment.