Skip to content

Commit

Permalink
fix(client): use more friendly config (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
DVKunion authored Jul 21, 2023
1 parent 41c5ce8 commit 99c98fd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ dist/
.secret
node_modules
bootstrap
.s/
.s/
.seamoom
3 changes: 2 additions & 1 deletion pkg/client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type proxyConfig struct {

var (
singleton *clientConfig
configPath = ".config"
configPath = ".seamoom"
)

func Config() *clientConfig {
Expand Down Expand Up @@ -62,6 +62,7 @@ func (c *clientConfig) Save() error {
if err := toml.NewEncoder(&buf).Encode(c); err != nil {
return err
}

fd, err := os.OpenFile(configPath, os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return err
Expand Down
14 changes: 9 additions & 5 deletions pkg/client/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ package client
import (
"context"
"crypto/tls"
"github.com/DVKunion/SeaMoon/pkg/consts"
"github.com/DVKunion/SeaMoon/pkg/utils"
"github.com/google/martian/v3"
log "github.com/sirupsen/logrus"
"net"
"net/http"
"net/url"
"strings"
"time"

"github.com/google/martian/v3"
log "github.com/sirupsen/logrus"

"github.com/DVKunion/SeaMoon/pkg/consts"
"github.com/DVKunion/SeaMoon/pkg/utils"
)

func HttpController(ctx context.Context, sg *SigGroup) {
Expand All @@ -27,7 +29,9 @@ func HttpController(ctx context.Context, sg *SigGroup) {
}
var proxyAddr string
for _, p := range Config().ProxyAddr {
if strings.HasPrefix(p, "http-proxy") {
if strings.HasPrefix(p, "http://") || strings.HasPrefix(p, "https://") {
proxyAddr = p
} else if strings.HasPrefix(p, "http-proxy") {
proxyAddr = "http://" + p
}
}
Expand Down
10 changes: 4 additions & 6 deletions pkg/client/socks.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@ func Socks5Controller(ctx context.Context, sg *SigGroup) {
}
var proxyAddr string
for _, p := range Config().ProxyAddr {
if strings.HasPrefix(p, "socks-proxy") {
if consts.Version == "dev" {
proxyAddr = "ws://127.0.0.1:8888"
} else {
proxyAddr = "ws://" + p
}
if strings.HasPrefix(p, "ws://") || strings.HasPrefix(p, "wss://") {
proxyAddr = p
} else if strings.HasPrefix(p, "socks-proxy") {
proxyAddr = "ws://" + p
}
}
if proxyAddr == "" {
Expand Down

0 comments on commit 99c98fd

Please sign in to comment.