Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
naiba committed May 10, 2023
1 parent 414e370 commit 7eab9d9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/agent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ on:
jobs:
deploy:
runs-on: ubuntu-latest
container:
# https://github.com/goreleaser/goreleaser-cross/issues/29
image: goreleaser/goreleaser-cross:v1.19.2
steps:
- uses: actions/checkout@master
with:
fetch-depth: 0
- uses: actions/setup-go@v2
with:
go-version: "^1.20.0"
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test-on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: "^1.20.0"
- name: Unit test
run: |
go test -v ./...
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: "^1.20.0"
- name: Unit test
run: |
go test -v ./...
Expand Down
10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,21 @@ var (
const (
delayWhenError = time.Second * 10 // Agent 重连间隔
networkTimeOut = time.Second * 5 // 普通网络超时
macOSChromeUA = ""
)

func init() {
flag.CommandLine.ParseErrorsWhitelist.UnknownFlags = true

http.DefaultClient.Timeout = time.Second * 5
httpClient.Transport = bpc.AddCloudFlareByPass(httpClient.Transport)
httpClient.Transport = bpc.AddCloudFlareByPass(httpClient.Transport, bpc.Options{
AddMissingHeaders: true,
Headers: map[string]string{
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.5",
"User-Agent": monitor.MacOSChromeUA,
},
})

ex, err := os.Executable()
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/monitor/myip.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
"strings"
"time"

fakeUa "github.com/EDDYCJY/fake-useragent"

"github.com/nezhahq/agent/pkg/util"
)

const MacOSChromeUA = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"

type geoIP struct {
CountryCode string `json:"country_code,omitempty"`
CountryCode2 string `json:"countryCode,omitempty"`
Expand Down Expand Up @@ -120,6 +120,6 @@ func httpGetWithUA(client *http.Client, url string) (*http.Response, error) {
if err != nil {
return nil, err
}
req.Header.Add("User-Agent", fakeUa.Random())
req.Header.Add("User-Agent", MacOSChromeUA)
return client.Do(req)
}

0 comments on commit 7eab9d9

Please sign in to comment.