1
0
mirror of https://github.com/nitezs/sub2sing-box.git synced 2024-12-23 22:04:41 -05:00
This commit is contained in:
Nite07 2024-09-19 18:12:24 +08:00
parent 89bb0d03e0
commit a1dcc1867f
19 changed files with 69 additions and 49 deletions

View File

@ -2,9 +2,10 @@ package handler
import ( import (
"encoding/json" "encoding/json"
"sub2sing-box/common"
"sub2sing-box/model" "github.com/nitezs/sub2sing-box/common"
"sub2sing-box/util" "github.com/nitezs/sub2sing-box/model"
"github.com/nitezs/sub2sing-box/util"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

View File

@ -6,7 +6,8 @@ import (
"html/template" "html/template"
"net/http" "net/http"
"strconv" "strconv"
"sub2sing-box/api/handler"
"github.com/nitezs/sub2sing-box/api/handler"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )

View File

@ -5,8 +5,9 @@ import (
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
"sub2sing-box/common"
"sub2sing-box/model" "github.com/nitezs/sub2sing-box/common"
"github.com/nitezs/sub2sing-box/model"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -79,7 +80,7 @@ func convertRun(cmd *cobra.Command, args []string) {
func loadConfig() { func loadConfig() {
if config == "" { if config == "" {
if wd, err := os.Getwd(); err == nil { if wd, err := os.Getwd(); err == nil {
config = filepath.Join(wd, "sub2sing-box.json") config = filepath.Join(wd, "github.com/nitezs/sub2sing-box.json")
if _, err := os.Stat(config); os.IsNotExist(err) { if _, err := os.Stat(config); os.IsNotExist(err) {
return return
} }

View File

@ -1,7 +1,7 @@
package cmd package cmd
import ( import (
"sub2sing-box/api" "github.com/nitezs/sub2sing-box/api"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )

View File

@ -2,7 +2,8 @@ package cmd
import ( import (
"fmt" "fmt"
"sub2sing-box/constant"
"github.com/nitezs/sub2sing-box/constant"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )

View File

@ -9,10 +9,11 @@ import (
"regexp" "regexp"
"sort" "sort"
"strings" "strings"
C "sub2sing-box/constant"
"sub2sing-box/model" C "github.com/nitezs/sub2sing-box/constant"
"sub2sing-box/parser" "github.com/nitezs/sub2sing-box/model"
"sub2sing-box/util" "github.com/nitezs/sub2sing-box/parser"
"github.com/nitezs/sub2sing-box/util"
) )
func Convert( func Convert(

2
go.mod
View File

@ -1,4 +1,4 @@
module sub2sing-box module github.com/nitezs/sub2sing-box
go 1.21.5 go 1.21.5

View File

@ -2,7 +2,8 @@ package main
import ( import (
"fmt" "fmt"
"sub2sing-box/cmd"
"github.com/nitezs/sub2sing-box/cmd"
) )
func main() { func main() {

View File

@ -5,7 +5,8 @@ import (
"errors" "errors"
"reflect" "reflect"
"strings" "strings"
C "sub2sing-box/constant"
C "github.com/nitezs/sub2sing-box/constant"
) )
type _Outbound struct { type _Outbound struct {
@ -83,6 +84,9 @@ func (h *Outbound) MarshalJSON() ([]byte, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
if rawOptions == nil {
return json.Marshal((*_Outbound)(h))
}
result := make(map[string]any) result := make(map[string]any)
result["type"] = h.Type result["type"] = h.Type
result["tag"] = h.Tag result["tag"] = h.Tag

View File

@ -1,7 +1,7 @@
package model package model
import ( import (
C "sub2sing-box/constant" C "github.com/nitezs/sub2sing-box/constant"
"golang.org/x/text/collate" "golang.org/x/text/collate"
"golang.org/x/text/language" "golang.org/x/text/language"

View File

@ -5,8 +5,9 @@ import (
"net/url" "net/url"
"strconv" "strconv"
"strings" "strings"
"sub2sing-box/constant"
"sub2sing-box/model" "github.com/nitezs/sub2sing-box/constant"
"github.com/nitezs/sub2sing-box/model"
) )
func ParseHysteria(proxy string) (model.Outbound, error) { func ParseHysteria(proxy string) (model.Outbound, error) {

View File

@ -4,8 +4,9 @@ import (
"fmt" "fmt"
"net/url" "net/url"
"strings" "strings"
"sub2sing-box/constant"
"sub2sing-box/model" "github.com/nitezs/sub2sing-box/constant"
"github.com/nitezs/sub2sing-box/model"
) )
func ParseHysteria2(proxy string) (model.Outbound, error) { func ParseHysteria2(proxy string) (model.Outbound, error) {

View File

@ -1,8 +1,8 @@
package parser package parser
import ( import (
"sub2sing-box/constant" "github.com/nitezs/sub2sing-box/constant"
"sub2sing-box/model" "github.com/nitezs/sub2sing-box/model"
) )
var ParserMap map[string]func(string) (model.Outbound, error) = map[string]func(string) (model.Outbound, error){ var ParserMap map[string]func(string) (model.Outbound, error) = map[string]func(string) (model.Outbound, error){

View File

@ -4,9 +4,10 @@ import (
"fmt" "fmt"
"net/url" "net/url"
"strings" "strings"
"sub2sing-box/constant"
"sub2sing-box/model" "github.com/nitezs/sub2sing-box/constant"
"sub2sing-box/util" "github.com/nitezs/sub2sing-box/model"
"github.com/nitezs/sub2sing-box/util"
) )
func ParseShadowsocks(proxy string) (model.Outbound, error) { func ParseShadowsocks(proxy string) (model.Outbound, error) {

View File

@ -4,8 +4,9 @@ import (
"fmt" "fmt"
"net/url" "net/url"
"strings" "strings"
"sub2sing-box/constant"
"sub2sing-box/model" "github.com/nitezs/sub2sing-box/constant"
"github.com/nitezs/sub2sing-box/model"
) )
func ParseTrojan(proxy string) (model.Outbound, error) { func ParseTrojan(proxy string) (model.Outbound, error) {

View File

@ -4,8 +4,9 @@ import (
"fmt" "fmt"
"net/url" "net/url"
"strings" "strings"
"sub2sing-box/constant"
"sub2sing-box/model" "github.com/nitezs/sub2sing-box/constant"
"github.com/nitezs/sub2sing-box/model"
) )
func ParseVless(proxy string) (model.Outbound, error) { func ParseVless(proxy string) (model.Outbound, error) {

View File

@ -5,9 +5,10 @@ import (
"net/url" "net/url"
"strconv" "strconv"
"strings" "strings"
"sub2sing-box/constant"
"sub2sing-box/model" "github.com/nitezs/sub2sing-box/constant"
"sub2sing-box/util" "github.com/nitezs/sub2sing-box/model"
"github.com/nitezs/sub2sing-box/util"
) )
func ParseVmess(proxy string) (model.Outbound, error) { func ParseVmess(proxy string) (model.Outbound, error) {

View File

@ -15,18 +15,15 @@
"detour": "direct" "detour": "direct"
}, },
{ {
"tag": "remote", "tag": "fakeip",
"address": "fakeip" "address": "fakeip"
} }
], ],
"rules": [ "rules": [
{ {
"outbound": "any", "outbound": "any",
"server": "local" "server": "local",
}, "disable_cache": true
{
"query_type": ["A", "AAAA"],
"server": "remote"
}, },
{ {
"clash_mode": "Direct", "clash_mode": "Direct",
@ -45,14 +42,19 @@
"mode": "and", "mode": "and",
"rules": [ "rules": [
{ {
"rule_set": "geosite-geolocation-!cn" "rule_set": "geosite-geolocation-!cn",
"invert": true
}, },
{ {
"rule_set": "geoip-cn" "rule_set": "geoip-cn"
} }
], ],
"server": "google", "server": "google",
"client_subnet": "114.114.114.114" "client_subnet": "114.114.114.114/24"
},
{
"query_type": ["A", "AAAA"],
"server": "fakeip"
} }
], ],
"fakeip": { "fakeip": {

View File

@ -15,18 +15,15 @@
"detour": "direct" "detour": "direct"
}, },
{ {
"tag": "remote", "tag": "fakeip",
"address": "fakeip" "address": "fakeip"
} }
], ],
"rules": [ "rules": [
{ {
"outbound": "any", "outbound": "any",
"server": "local" "server": "local",
}, "disable_cache": true
{
"query_type": ["A", "AAAA"],
"server": "remote"
}, },
{ {
"clash_mode": "Direct", "clash_mode": "Direct",
@ -45,14 +42,19 @@
"mode": "and", "mode": "and",
"rules": [ "rules": [
{ {
"rule_set": "geosite-geolocation-!cn" "rule_set": "geosite-geolocation-!cn",
"invert": true
}, },
{ {
"rule_set": "geoip-cn" "rule_set": "geoip-cn"
} }
], ],
"server": "google", "server": "google",
"client_subnet": "114.114.114.114" "client_subnet": "114.114.114.114/24"
},
{
"query_type": ["A", "AAAA"],
"server": "fakeip"
} }
], ],
"fakeip": { "fakeip": {