mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-09-02 08:21:56 +03:00
Linting
This commit is contained in:
+1
-1
@@ -87,7 +87,7 @@ func runAccessGetIP(ntw *network.Network, protocol string) net.IP {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := client.Get("https://ifconfig.co")
|
resp, err := client.Get("https://ifconfig.co") // nolint: bodyclose, noctx
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ func runGenerateSecret(cli *CLI) {
|
|||||||
secret := mtglib.GenerateSecret(cli.GenerateSecret.HostName)
|
secret := mtglib.GenerateSecret(cli.GenerateSecret.HostName)
|
||||||
|
|
||||||
if cli.GenerateSecret.Hex {
|
if cli.GenerateSecret.Hex {
|
||||||
fmt.Println(secret.Hex())
|
fmt.Println(secret.Hex()) // nolint: forbidigo
|
||||||
} else {
|
} else {
|
||||||
fmt.Println(secret.Base64())
|
fmt.Println(secret.Base64()) // nolint: forbidigo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ func (c *configTypeHostPort) UnmarshalText(data []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c configTypeHostPort) MarshalText() ([]byte, error) {
|
func (c configTypeHostPort) MarshalText() ([]byte, error) { // nolint: unparam
|
||||||
return []byte(c.String()), nil
|
return []byte(c.String()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,7 +118,7 @@ func (c *configTypeBytes) UnmarshalText(data []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c configTypeBytes) MarshalText() ([]byte, error) {
|
func (c configTypeBytes) MarshalText() ([]byte, error) { // nolint: unparam
|
||||||
return []byte(c.String()), nil
|
return []byte(c.String()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,7 +155,7 @@ func (c *configTypePreferIP) UnmarshalText(data []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c configTypePreferIP) MarshalText() ([]byte, error) {
|
func (c configTypePreferIP) MarshalText() ([]byte, error) { // nolint: unparam
|
||||||
return []byte(c.value), nil
|
return []byte(c.value), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,7 +194,7 @@ func (c *configTypeDuration) UnmarshalText(data []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c configTypeDuration) MarshalText() ([]byte, error) {
|
func (c configTypeDuration) MarshalText() ([]byte, error) { // nolint: unparam
|
||||||
return []byte(c.value.String()), nil
|
return []byte(c.value.String()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,7 +229,7 @@ func (c *configTypeFloat) UnmarshalJSON(data []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *configTypeFloat) MarshalText() ([]byte, error) {
|
func (c *configTypeFloat) MarshalText() ([]byte, error) { // nolint: unparam
|
||||||
return []byte(c.String()), nil
|
return []byte(c.String()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,7 +264,7 @@ func (c *configTypeIP) UnmarshalText(data []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *configTypeIP) MarshalText() ([]byte, error) {
|
func (c *configTypeIP) MarshalText() ([]byte, error) { // nolint: unparam
|
||||||
return []byte(c.String()), nil
|
return []byte(c.String()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -303,7 +303,7 @@ func (c *configTypeURL) UnmarshalText(data []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *configTypeURL) MarshalText() ([]byte, error) {
|
func (c *configTypeURL) MarshalText() ([]byte, error) { // nolint: unparam
|
||||||
return []byte(c.String()), nil
|
return []byte(c.String()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -343,7 +343,7 @@ func (c *configTypeMetricPrefix) UnmarshalText(data []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c configTypeMetricPrefix) MarshalText() ([]byte, error) {
|
func (c configTypeMetricPrefix) MarshalText() ([]byte, error) { // nolint: unparam
|
||||||
return []byte(c.String()), nil
|
return []byte(c.String()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -371,7 +371,7 @@ func (c *configTypeHTTPPath) UnmarshalText(data []byte) error { // nolint: unpar
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c configTypeHTTPPath) MarshalText() ([]byte, error) {
|
func (c configTypeHTTPPath) MarshalText() ([]byte, error) { // nolint: unparam
|
||||||
return []byte(c.String()), nil
|
return []byte(c.String()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,17 +10,18 @@ import (
|
|||||||
var version = "dev" // has to be set by ldflags
|
var version = "dev" // has to be set by ldflags
|
||||||
|
|
||||||
type CLI struct {
|
type CLI struct {
|
||||||
GenerateSecret struct {
|
GenerateSecret struct { // nolint: govet
|
||||||
HostName string `arg optional help:"Hostname to use for domain fronting. Default is '${domain_front}'." name:"hostname" default:"${domain_front}"`
|
HostName string `arg optional help:"Hostname to use for domain fronting. Default is '${domain_front}'." name:"hostname" default:"${domain_front}"` // nolint: lll, govet
|
||||||
Hex bool `help:"Print secret in hex encoding."`
|
Hex bool `help:"Print secret in hex encoding."`
|
||||||
} `cmd help:"Generate new proxy secret."`
|
} `cmd help:"Generate new proxy secret."`
|
||||||
Access struct {
|
Access struct { // nolint: govet
|
||||||
ConfigPath string `arg required type:"existingfile" help:"Path to the configuration file." name:"config-path"`
|
ConfigPath string `arg required type:"existingfile" help:"Path to the configuration file." name:"config-path"` // nolint: lll, govet
|
||||||
Hex bool `help:"Print secret in hex encoding."`
|
Hex bool `help:"Print secret in hex encoding."`
|
||||||
} `cmd help:"Print access information."`
|
} `cmd help:"Print access information."`
|
||||||
Run struct {
|
Run struct { // nolint: govet
|
||||||
ConfigPath string `arg required type:"existingfile" help:"Path to the configuration file." name:"config-path"`
|
ConfigPath string `arg required type:"existingfile" help:"Path to the configuration file." name:"config-path"` // nolint: lll, govet
|
||||||
} `cmd help:"Run proxy."`
|
} `cmd help:"Run proxy."`
|
||||||
|
Version kong.VersionFlag `help:"Print version."`
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -30,6 +31,7 @@ func main() {
|
|||||||
ctx := kong.Parse(cli, kong.Vars{
|
ctx := kong.Parse(cli, kong.Vars{
|
||||||
"domain_front": "amazonaws.com",
|
"domain_front": "amazonaws.com",
|
||||||
"config_path": "/etc/mtg.toml",
|
"config_path": "/etc/mtg.toml",
|
||||||
|
"version": version,
|
||||||
})
|
})
|
||||||
|
|
||||||
switch ctx.Command() {
|
switch ctx.Command() {
|
||||||
|
|||||||
+2
-2
@@ -15,8 +15,8 @@ type Secret struct {
|
|||||||
Host string
|
Host string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Secret) MarshalText() ([]byte, error) {
|
func (s Secret) MarshalText() ([]byte, error) {
|
||||||
if s == nil {
|
if s.Key == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ func makeNetwork(conf *config) (*network.Network, error) {
|
|||||||
return nil, fmt.Errorf("cannot build a default dialer: %w", err)
|
return nil, fmt.Errorf("cannot build a default dialer: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
proxyURLs := make([]*url.URL, len(conf.Network.Proxies))
|
proxyURLs := make([]*url.URL, 0, len(conf.Network.Proxies))
|
||||||
|
|
||||||
for _, v := range conf.Network.Proxies {
|
for _, v := range conf.Network.Proxies {
|
||||||
if value := v.Value(nil); value != nil {
|
if value := v.Value(nil); value != nil {
|
||||||
@@ -41,7 +41,6 @@ func makeNetwork(conf *config) (*network.Network, error) {
|
|||||||
return network.NewNetwork(baseDialer, dohIP, httpTimeout)
|
return network.NewNetwork(baseDialer, dohIP, httpTimeout)
|
||||||
case 1:
|
case 1:
|
||||||
socksDialer, err := network.NewSocks5Dialer(baseDialer, proxyURLs[0])
|
socksDialer, err := network.NewSocks5Dialer(baseDialer, proxyURLs[0])
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("cannot build socks5 dialer: %w", err)
|
return nil, fmt.Errorf("cannot build socks5 dialer: %w", err)
|
||||||
}
|
}
|
||||||
@@ -51,7 +50,6 @@ func makeNetwork(conf *config) (*network.Network, error) {
|
|||||||
|
|
||||||
socksDialer, err := network.NewLoadBalancedSocks5Dialer(baseDialer, proxyURLs)
|
socksDialer, err := network.NewLoadBalancedSocks5Dialer(baseDialer, proxyURLs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
return nil, fmt.Errorf("cannot build socks5 dialer: %w", err)
|
return nil, fmt.Errorf("cannot build socks5 dialer: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,6 +57,6 @@ func makeNetwork(conf *config) (*network.Network, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func exhaustResponse(response *http.Response) {
|
func exhaustResponse(response *http.Response) {
|
||||||
io.Copy(ioutil.Discard, response.Body)
|
io.Copy(ioutil.Discard, response.Body) // nolint: errcheck
|
||||||
response.Body.Close()
|
response.Body.Close()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user