diff --git a/.github/workflows/dev-build.yml b/.github/workflows/dev-build.yml index 7dbfcc1..80ce07b 100644 --- a/.github/workflows/dev-build.yml +++ b/.github/workflows/dev-build.yml @@ -21,7 +21,7 @@ jobs: - name: Checkout code uses: actions/checkout@v2 - name: Build - run: mkdir dist && go build -o dist + run: mkdir dist && go build -tags "full" -o dist - name: Upload Binary uses: actions/upload-artifact@v1 with: diff --git a/build-all.sh b/build-all.sh index b7bff33..7fd5504 100755 --- a/build-all.sh +++ b/build-all.sh @@ -35,7 +35,7 @@ for PLATFORM in $PLATFORMS; do GOOS=${PLATFORM%/*} GOARCH=${PLATFORM#*/} ZIP_FILENAME="trojan-go-${GOOS}-${GOARCH}.zip" - CMD="CGO_ENABLE=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -o temp $@ -ldflags=\"-s -w\"" + CMD="CGO_ENABLE=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -tags \"full\" -o temp $@ -ldflags=\"-s -w\"" echo "${CMD}" eval $CMD || FAILURES="${FAILURES} ${PLATFORM}" zip -j release/$ZIP_FILENAME temp/* ./*.dat diff --git a/build.sh b/build.sh index cc6d4c0..79d1501 100755 --- a/build.sh +++ b/build.sh @@ -1 +1 @@ -CGO_ENABLE=0 go build -ldflags="-s -w" +CGO_ENABLE=0 go build -tags "full" -ldflags="-s -w" diff --git a/build/api.go b/build/api.go new file mode 100644 index 0000000..8ca581b --- /dev/null +++ b/build/api.go @@ -0,0 +1,7 @@ +// +build api full + +package build + +import ( + _ "github.com/p4gefau1t/trojan-go/api" +) diff --git a/build/cert.go b/build/cert.go new file mode 100644 index 0000000..7ac84e5 --- /dev/null +++ b/build/cert.go @@ -0,0 +1,7 @@ +// +build cert full + +package build + +import ( + _ "github.com/p4gefau1t/trojan-go/cert" +) diff --git a/build/client.go b/build/client.go new file mode 100644 index 0000000..f855ca0 --- /dev/null +++ b/build/client.go @@ -0,0 +1,7 @@ +// +build client full + +package build + +import ( + _ "github.com/p4gefau1t/trojan-go/proxy/client" +) diff --git a/build/full.go b/build/full.go new file mode 100644 index 0000000..2b03b29 --- /dev/null +++ b/build/full.go @@ -0,0 +1,8 @@ +// +build full + +package build + +import ( + _ "github.com/p4gefau1t/trojan-go/daemon" + _ "github.com/p4gefau1t/trojan-go/easy" +) diff --git a/build/mysql.go b/build/mysql.go new file mode 100644 index 0000000..47c71e7 --- /dev/null +++ b/build/mysql.go @@ -0,0 +1,7 @@ +// +build mysql full + +package build + +import ( + _ "github.com/p4gefau1t/trojan-go/stat/mysql" +) diff --git a/build/relay.go b/build/relay.go new file mode 100644 index 0000000..3643225 --- /dev/null +++ b/build/relay.go @@ -0,0 +1,7 @@ +// +build relay full + +package build + +import ( + _ "github.com/p4gefau1t/trojan-go/proxy/relay" +) diff --git a/build/router.go b/build/router.go new file mode 100644 index 0000000..365d161 --- /dev/null +++ b/build/router.go @@ -0,0 +1,7 @@ +// +build router full + +package build + +import ( + _ "github.com/p4gefau1t/trojan-go/router/mixed" +) diff --git a/build/server.go b/build/server.go new file mode 100644 index 0000000..e980c3e --- /dev/null +++ b/build/server.go @@ -0,0 +1,7 @@ +// +build server full + +package build + +import ( + _ "github.com/p4gefau1t/trojan-go/proxy/server" +) diff --git a/main.go b/main.go index 5d02248..e7c637e 100644 --- a/main.go +++ b/main.go @@ -5,22 +5,13 @@ import ( "github.com/p4gefau1t/trojan-go/common" "github.com/p4gefau1t/trojan-go/log" - - //the following modules are optional - //you can comment some of them if you don't need them - _ "github.com/p4gefau1t/trojan-go/api" - _ "github.com/p4gefau1t/trojan-go/cert" - _ "github.com/p4gefau1t/trojan-go/daemon" - _ "github.com/p4gefau1t/trojan-go/easy" - _ "github.com/p4gefau1t/trojan-go/log/golog" - _ "github.com/p4gefau1t/trojan-go/proxy/client" - _ "github.com/p4gefau1t/trojan-go/proxy/relay" - _ "github.com/p4gefau1t/trojan-go/proxy/server" - _ "github.com/p4gefau1t/trojan-go/router/mixed" - _ "github.com/p4gefau1t/trojan-go/stat/db" + _ "github.com/p4gefau1t/trojan-go/stat/memory" + _ "github.com/p4gefau1t/trojan-go/log/golog" _ "github.com/p4gefau1t/trojan-go/version" //_ "github.com/p4gefau1t/trojan-go/log/simplelog" + + _ "github.com/p4gefau1t/trojan-go/build" ) func main() { diff --git a/stat/db/db.go b/stat/mysql/mysql.go similarity index 99% rename from stat/db/db.go rename to stat/mysql/mysql.go index da99681..e9885ac 100644 --- a/stat/db/db.go +++ b/stat/mysql/mysql.go @@ -1,4 +1,4 @@ -package db +package mysql import ( "context" diff --git a/stat/db/db_test.go b/stat/mysql/mysql_test.go similarity index 98% rename from stat/db/db_test.go rename to stat/mysql/mysql_test.go index 3f396ae..6908d10 100644 --- a/stat/db/db_test.go +++ b/stat/mysql/mysql_test.go @@ -1,4 +1,4 @@ -package db +package mysql import ( "context" diff --git a/update/update.go b/update/update.go deleted file mode 100644 index 928bf8c..0000000 --- a/update/update.go +++ /dev/null @@ -1,50 +0,0 @@ -package update - -import ( - "io" - "net/http" - "os" - - "github.com/p4gefau1t/trojan-go/common" -) - -func downloadFile(url string, filepath string) error { - resp, err := http.Get(url) - if err != nil { - return err - } - defer resp.Body.Close() - - out, err := os.Create(filepath) - if err != nil { - return err - } - defer out.Close() - - _, err = io.Copy(out, resp.Body) - if err != nil { - return err - } - return nil -} - -func downloadGeoSite() error { - filename := "geosite.dat" - url := "https://github.com/v2ray/domain-list-community/raw/release/dlc.dat" - return downloadFile(url, filename) -} - -func downloadGeoIP() error { - filename := "geoip.dat" - url := "https://raw.githubusercontent.com/v2ray/geoip/release/geoip.dat" - return downloadFile(url, filename) -} - -type updateOption struct { - args *string - common.OptionHandler -} - -func init() { - // TODO auto updating -}