Migration: go 1.18

This commit is contained in:
yaling888 2022-03-16 22:00:20 +08:00
parent 346d817dba
commit b8d635a4b3
12 changed files with 15 additions and 62 deletions

View file

@ -16,13 +16,12 @@ jobs:
#with: #with:
# go-version: ${{ steps.version.outputs.go_version }} # go-version: ${{ steps.version.outputs.go_version }}
with: with:
go-version: 1.18.0-rc1 go-version: 1.18.x
stable: false
- name: golangci-lint - name: golangci-lint
#uses: golangci/golangci-lint-action@v3 #uses: golangci/golangci-lint-action@v3
#with: #with:
# version: latest # version: latest
run: | run: |
go install github.com/golangci/golangci-lint/cmd/golangci-lint@93a0015 go install github.com/golangci/golangci-lint/cmd/golangci-lint@ec95236
golangci-lint run ./... golangci-lint run ./...

View file

@ -14,8 +14,7 @@ jobs:
#with: #with:
# go-version: ${{ steps.version.outputs.go_version }} # go-version: ${{ steps.version.outputs.go_version }}
with: with:
go-version: 1.18.0-rc1 go-version: 1.18.x
stable: false
- name: Check out code into the Go module directory - name: Check out code into the Go module directory
uses: actions/checkout@v3 uses: actions/checkout@v3

View file

@ -5,6 +5,8 @@ linters:
- staticcheck - staticcheck
- govet - govet
# - gci # - gci
- gofmt
- goimports
linters-settings: linters-settings:
gci: gci:

View file

@ -19,7 +19,7 @@ const (
type TUNStack int type TUNStack int
// UnmarshalYAML unserialize TUNStack with yaml // UnmarshalYAML unserialize TUNStack with yaml
func (e *TUNStack) UnmarshalYAML(unmarshal func(interface{}) error) error { func (e *TUNStack) UnmarshalYAML(unmarshal func(any) error) error {
var tp string var tp string
if err := unmarshal(&tp); err != nil { if err := unmarshal(&tp); err != nil {
return err return err
@ -33,7 +33,7 @@ func (e *TUNStack) UnmarshalYAML(unmarshal func(interface{}) error) error {
} }
// MarshalYAML serialize TUNStack with yaml // MarshalYAML serialize TUNStack with yaml
func (e TUNStack) MarshalYAML() (interface{}, error) { func (e TUNStack) MarshalYAML() (any, error) {
return e.String(), nil return e.String(), nil
} }

2
go.mod
View file

@ -27,7 +27,7 @@ require (
golang.zx2c4.com/wireguard/windows v0.5.3 golang.zx2c4.com/wireguard/windows v0.5.3
google.golang.org/protobuf v1.27.1 google.golang.org/protobuf v1.27.1
gopkg.in/yaml.v2 v2.4.0 gopkg.in/yaml.v2 v2.4.0
gvisor.dev/gvisor v0.0.0-20220314190221-89a04115dfa4 gvisor.dev/gvisor v0.0.0-20220315202956-f1399ecf1672
) )
require ( require (

4
go.sum
View file

@ -163,5 +163,5 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gvisor.dev/gvisor v0.0.0-20220314190221-89a04115dfa4 h1:7xad6H5GS+ihL8OQGSZjndLmGTPqyXFLxV7viYKLZ30= gvisor.dev/gvisor v0.0.0-20220315202956-f1399ecf1672 h1:aXIFpjZYl3zv2rQyr4rSit5Uq0k7BVXC8lJaDa4Cg7M=
gvisor.dev/gvisor v0.0.0-20220314190221-89a04115dfa4/go.mod h1:V4WNP2Uwtx69eOhvLDSQ734EaTJTaBI3P8KgRAlROsg= gvisor.dev/gvisor v0.0.0-20220315202956-f1399ecf1672/go.mod h1:V4WNP2Uwtx69eOhvLDSQ734EaTJTaBI3P8KgRAlROsg=

View file

@ -1,41 +0,0 @@
//go:build windows
// +build windows
/* SPDX-License-Identifier: MIT
*
* Copyright (C) 2019-2021 WireGuard LLC. All Rights Reserved.
*/
package commons
import (
"errors"
"log"
"sync"
"time"
"golang.org/x/sys/windows"
"golang.org/x/sys/windows/svc"
)
var (
startedAtBoot bool
startedAtBootOnce sync.Once
)
func StartedAtBoot() bool {
startedAtBootOnce.Do(func() {
if isService, err := svc.IsWindowsService(); err == nil && !isService {
return
}
if reason, err := svc.DynamicStartReason(); err == nil {
startedAtBoot = (reason&svc.StartReasonAuto) != 0 || (reason&svc.StartReasonDelayedAuto) != 0
} else if errors.Is(err, windows.ERROR_PROC_NOT_FOUND) {
// TODO: Below this line is Windows 7 compatibility code, which hopefully we can delete at some point.
startedAtBoot = windows.DurationSinceBoot() < time.Minute*10
} else {
log.Printf("Unable to determine service start reason: %v", err)
}
})
return startedAtBoot
}

View file

@ -11,6 +11,7 @@ import (
"github.com/Dreamacro/clash/log" "github.com/Dreamacro/clash/log"
"golang.org/x/sys/windows" "golang.org/x/sys/windows"
"golang.zx2c4.com/wireguard/windows/services"
"golang.zx2c4.com/wireguard/windows/tunnel/winipcfg" "golang.zx2c4.com/wireguard/windows/tunnel/winipcfg"
) )
@ -24,7 +25,7 @@ func GetAutoDetectInterface() (string, error) {
} }
func ConfigInterfaceAddress(dev device.Device, addr netip.Prefix, forceMTU int, autoRoute bool) error { func ConfigInterfaceAddress(dev device.Device, addr netip.Prefix, forceMTU int, autoRoute bool) error {
retryOnFailure := StartedAtBoot() retryOnFailure := services.StartedAtBoot()
tryTimes := 0 tryTimes := 0
var err error var err error
startOver: startOver:

View file

@ -1,5 +1,4 @@
//go:build !noasm //go:build !noasm
// +build !noasm
package tcpip package tcpip

View file

@ -97,9 +97,3 @@ func newLog(logLevel LogLevel, format string, v ...any) *Event {
Payload: fmt.Sprintf(format, v...), Payload: fmt.Sprintf(format, v...),
} }
} }
func PrintLog(logLevel LogLevel, format string, v ...interface{}) {
event := newLog(logLevel, format, v...)
logCh <- event
print(event)
}

View file

@ -56,5 +56,5 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
gotest.tools/v3 v3.1.0 // indirect gotest.tools/v3 v3.1.0 // indirect
gvisor.dev/gvisor v0.0.0-20220314190221-89a04115dfa4 // indirect gvisor.dev/gvisor v0.0.0-20220315202956-f1399ecf1672 // indirect
) )

View file

@ -1413,8 +1413,8 @@ gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
gotest.tools/v3 v3.0.3/go.mod h1:Z7Lb0S5l+klDB31fvDQX8ss/FlKDxtlFlw3Oa8Ymbl8= gotest.tools/v3 v3.0.3/go.mod h1:Z7Lb0S5l+klDB31fvDQX8ss/FlKDxtlFlw3Oa8Ymbl8=
gotest.tools/v3 v3.1.0 h1:rVV8Tcg/8jHUkPUorwjaMTtemIMVXfIPKiOqnhEhakk= gotest.tools/v3 v3.1.0 h1:rVV8Tcg/8jHUkPUorwjaMTtemIMVXfIPKiOqnhEhakk=
gotest.tools/v3 v3.1.0/go.mod h1:fHy7eyTmJFO5bQbUsEGQ1v4m2J3Jz9eWL54TP2/ZuYQ= gotest.tools/v3 v3.1.0/go.mod h1:fHy7eyTmJFO5bQbUsEGQ1v4m2J3Jz9eWL54TP2/ZuYQ=
gvisor.dev/gvisor v0.0.0-20220314190221-89a04115dfa4 h1:7xad6H5GS+ihL8OQGSZjndLmGTPqyXFLxV7viYKLZ30= gvisor.dev/gvisor v0.0.0-20220315202956-f1399ecf1672 h1:aXIFpjZYl3zv2rQyr4rSit5Uq0k7BVXC8lJaDa4Cg7M=
gvisor.dev/gvisor v0.0.0-20220314190221-89a04115dfa4/go.mod h1:V4WNP2Uwtx69eOhvLDSQ734EaTJTaBI3P8KgRAlROsg= gvisor.dev/gvisor v0.0.0-20220315202956-f1399ecf1672/go.mod h1:V4WNP2Uwtx69eOhvLDSQ734EaTJTaBI3P8KgRAlROsg=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=