Skip to content

Commit

Permalink
sem
Browse files Browse the repository at this point in the history
  • Loading branch information
BapiGso committed Nov 1, 2024
1 parent 91153b3 commit f8157ba
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
2 changes: 1 addition & 1 deletion core/sem/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func Index(c echo.Context) error {
if err != nil {
return err
}
if err := os.WriteFile("gopanel_frps.json", data, 0644); err != nil {
if err := os.WriteFile("gopanel_sem.json", data, 0644); err != nil {
return err
}
return c.JSON(200, "success")
Expand Down
46 changes: 31 additions & 15 deletions core/sem/sem.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,50 @@
package sem

import (
"errors"
"fmt"
"github.com/xtls/xray-core/common/cmdarg"
"github.com/xtls/xray-core/core"
"os"
"strings"
)

type Arg []string

func (c *Arg) String() string {
return strings.Join(*c, " ")
}

// Set is the method flag package calls
func (c *Arg) Set(value string) error {
*c = append(*c, value)
return nil
}

func startXray() (core.Server, error) {
cfg := func() cmdarg.Arg {
if fileExists("gopanel_sem.json") {
return cmdarg.Arg{"gopanel_sem.json"}
}
//fmt.Println(123)
return cmdarg.Arg{"stdin:"}
}()
// config, err := core.LoadConfig(getConfigFormat(), configFiles[0], configFiles)

c, err := core.LoadConfig("json", cfg)
cfgFile := "gopanel_sem.json"
if !fileExists(cfgFile) {
return nil, fmt.Errorf("config file %s does not exist", cfgFile)
}

cfg := Arg{cfgFile}

file, err := os.Open("gopanel_sem.json")
if err != nil {
return nil, err
}
defer file.Close() // 确保文件在函数结束时被关闭

c, err := core.LoadConfig("json", file)
if err != nil {
return nil, fmt.Errorf("failed to load config files: [", cfg, "]")
return nil, err
}
if c == nil {
return nil, fmt.Errorf("c is nil")
return nil, fmt.Errorf("loaded config is nil", cfg)
}
fmt.Println(c)

server, err := core.New(c)
if err != nil {
return nil, errors.New("failed to create server")
return nil, fmt.Errorf("failed to create server: %w", err)
}

return server, nil
Expand Down

0 comments on commit f8157ba

Please sign in to comment.