Skip to content

Commit

Permalink
fix golangci-lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
0pcom committed Sep 22, 2024
1 parent e09b250 commit e82d056
Show file tree
Hide file tree
Showing 43 changed files with 147 additions and 89 deletions.
2 changes: 1 addition & 1 deletion cmd/apps/skychat/commands/skychat.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ var RootCmd = &cobra.Command{
DisableSuggestions: true,
DisableFlagsInUseLine: true,
Version: buildinfo.Version(),
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {

appCl = app.NewClient(nil)
defer appCl.Close()
Expand Down
2 changes: 1 addition & 1 deletion cmd/apps/skysocks-client/commands/skysocks-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var RootCmd = &cobra.Command{
DisableSuggestions: true,
DisableFlagsInUseLine: true,
Version: buildinfo.Version(),
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
appCl := app.NewClient(nil)
defer appCl.Close()

Expand Down
2 changes: 1 addition & 1 deletion cmd/apps/skysocks/commands/skysocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var RootCmd = &cobra.Command{
DisableSuggestions: true,
DisableFlagsInUseLine: true,
Version: buildinfo.Version(),
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
appCl := app.NewClient(nil)
defer appCl.Close()

Expand Down
2 changes: 1 addition & 1 deletion cmd/apps/vpn-client/commands/vpn-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var RootCmd = &cobra.Command{
DisableSuggestions: true,
DisableFlagsInUseLine: true,
Version: buildinfo.Version(),
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {

var directIPsCh, nonDirectIPsCh = make(chan net.IP, 100), make(chan net.IP, 100)
defer close(directIPsCh)
Expand Down
6 changes: 3 additions & 3 deletions cmd/skywire-cli/commands/config/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var checkPKCmd = &cobra.Command{
Use: "check-pk <public-key>",
Short: "check a skywire public key",
Args: cobra.ExactArgs(1), // Require exactly one argument
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
if len(args) == 0 {
return
}
Expand All @@ -52,7 +52,7 @@ var checkPKCmd = &cobra.Command{
var genKeysCmd = &cobra.Command{
Use: "gen-keys",
Short: "generate public / secret keypair",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
pk, sk := cipher.GenerateKeyPair()
fmt.Println(pk)
fmt.Println(sk)
Expand Down Expand Up @@ -379,7 +379,7 @@ var genConfigCmd = &cobra.Command{
}
}
},
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {

log := logger
wasStdout := isStdout
Expand Down
6 changes: 3 additions & 3 deletions cmd/skywire-cli/commands/config/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func init() {
var servicesCmd = &cobra.Command{
Use: "svc",
Short: "update services-config.json file from config bootstrap service",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
log := logging.MustGetLogger("services_updater")

ctx, cancel := cmdutil.SignalContext(context.Background(), log)
Expand Down Expand Up @@ -56,7 +56,7 @@ var servicesCmd = &cobra.Command{
func fetchServicesConf() (servicesConf, error) {
var newConf servicesConf
var prodConf visorconfig.Services
prodResp, err := http.Get(serviceConfURL)
prodResp, err := http.Get(serviceConfURL) //nolint
if err != nil {
return newConf, err
}
Expand All @@ -72,7 +72,7 @@ func fetchServicesConf() (servicesConf, error) {
newConf.Prod = prodConf

var testConf visorconfig.Services
testResp, err := http.Get(testServiceConfURL)
testResp, err := http.Get(testServiceConfURL) //nolint
if err != nil {
return newConf, err
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/skywire-cli/commands/config/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func init() {
updateCmd.Flags().SortFlags = false
updateCmd.Flags().BoolVarP(&isUpdateEndpoints, "endpoints", "a", false, "update server endpoints")
updateCmd.Flags().StringVar(&logLevel, "log-level", "", "level of logging in config")
updateCmd.Flags().StringVarP(&serviceConfURL, "url", "b", skywire.ConfService, "service config URL")
updateCmd.Flags().StringVarP(&serviceConfURL, "url", "b", skywire.ProdConf.Conf, "service config URL")
updateCmd.Flags().BoolVarP(&isTestEnv, "testenv", "t", false, "use test deployment")
updateCmd.Flags().StringVar(&setPublicAutoconnect, "public-autoconn", "", "change public autoconnect configuration")
updateCmd.Flags().IntVar(&minHops, "set-minhop", -1, "change min hops value")
Expand Down Expand Up @@ -92,9 +92,9 @@ var updateCmd = &cobra.Command{
PreRun: func(_ *cobra.Command, _ []string) {
if isUpdateEndpoints && (serviceConfURL == "") {
if !isTestEnv {
serviceConfURL = skywire.ConfService
serviceConfURL = skywire.ProdConf.Conf
} else {
serviceConfURL = skywire.ConfServiceTest
serviceConfURL = skywire.TestConf.Conf
}
}
setDefaults()
Expand All @@ -107,7 +107,7 @@ var updateCmd = &cobra.Command{
conf = initUpdate()
if isUpdateEndpoints {
if isTestEnv {
serviceConfURL = skywire.ConfServiceTest
serviceConfURL = skywire.TestConf.Conf
}
mLog := logging.NewMasterLogger()
mLog.SetLevel(logrus.InfoLevel)
Expand Down
2 changes: 1 addition & 1 deletion cmd/skywire-cli/commands/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ var logCmd = &cobra.Command{
Use: "log",
Short: "survey & transport log collection",
Long: "Fetch health, survey, and transport logging from visors which are online in the uptime tracker\nhttp://ut.skywire.skycoin.com/uptimes?v=v2\nhttp://ut.skywire.skycoin.com/uptimes?v=v2&visors=<pk1>;<pk2>;<pk3>",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
log := logging.MustGetLogger("log-collecting")
fver, err := version.NewVersion("v1.3.17")
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/skywire-cli/commands/mdisc/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var RootCmd = &cobra.Command{
Short: "Query DMSG Discovery",
Long: `Query DMSG Discovery
list entries in dmsg discovery`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
dmsgclientkeys := internal.GetData(cacheFileDMSGD, mdURL+"/dmsg-discovery/entries", cacheFilesAge)
if isStats {
stats, _ := script.Echo(dmsgclientkeys).JQ(".[]").CountLines() //nolint
Expand Down
16 changes: 11 additions & 5 deletions cmd/skywire-cli/commands/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ var startCmd = &cobra.Command{
var stopCmd = &cobra.Command{
Use: "stop",
Short: "stop the " + serviceType + " client",
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
rpcClient, err := clirpc.Client(cmd.Flags())
if err != nil {
internal.PrintFatalError(cmd.Flags(), fmt.Errorf("unable to create RPC client: %w", err))
Expand All @@ -197,7 +197,7 @@ var stopCmd = &cobra.Command{
var statusCmd = &cobra.Command{
Use: "status",
Short: serviceType + " client status",
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
//TODO: check status of multiple clients
rpcClient, err := clirpc.Client(cmd.Flags())
if err != nil {
Expand All @@ -217,7 +217,10 @@ var statusCmd = &cobra.Command{
AppPort routing.Port `json:"app_port"`
}
var jsonAppStatus []appState
fmt.Fprintf(w, "---- All Proxy List -----------------------------------------------------\n\n")
_, err = fmt.Fprintf(w, "---- All Proxy List -----------------------------------------------------\n\n")
if err != nil {
internal.PrintFatalError(cmd.Flags(), fmt.Errorf("error on fmt.Fprintf: %w", err))
}
for _, state := range states {
for _, v := range state.AppConfig.Args {
if v == binaryName {
Expand Down Expand Up @@ -250,7 +253,10 @@ var statusCmd = &cobra.Command{
}
}
}
fmt.Fprintf(w, "-------------------------------------------------------------------------\n")
_, err = fmt.Fprintf(w, "-------------------------------------------------------------------------\n")
if err != nil {
internal.PrintFatalError(cmd.Flags(), fmt.Errorf("error on fmt.Fprintf: %w", err))
}
internal.Catch(cmd.Flags(), w.Flush())
internal.PrintOutput(cmd.Flags(), jsonAppStatus, b.String())
},
Expand Down Expand Up @@ -290,7 +296,7 @@ var listCmd = &cobra.Command{
Use: "list",
Short: "List servers",
Long: fmt.Sprintf("List %v servers from service discovery\n%v/api/services?type=%v\n%v/api/services?type=%v&country=US\n\nSet cache file location to \"\" to avoid using cache files", serviceType, svcDiscURL, serviceType, svcDiscURL, serviceType),
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
sds := internal.GetData(cacheFileSD, sdURL+"/api/services?type="+serviceType, cacheFilesAge)
if rawData {
script.Echo(string(pretty.Color(pretty.Pretty([]byte(sds)), nil))).Stdout() //nolint
Expand Down
4 changes: 2 additions & 2 deletions cmd/skywire-cli/commands/rewards/calc.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ var RootCmd = &cobra.Command{
Long: `
Collect surveys: skywire-cli log
Fetch uptimes: skywire-cli ut > ut.txt`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
var err error
if log == nil {
log = logging.MustGetLogger("rewards")
Expand Down Expand Up @@ -406,7 +406,7 @@ func init() {
var testCmd = &cobra.Command{
Use: "svc",
Short: "verify services in survey",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
var err error
if log == nil {
log = logging.MustGetLogger("rewards")
Expand Down
45 changes: 43 additions & 2 deletions cmd/skywire-cli/commands/rewards/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func init() {
uiCmd,
)
uiCmd.Flags().UintVarP(&webPort, "port", "p", scriptExecUint("${WEBPORT:-80}"), "port to serve")
uiCmd.Flags().UintVarP(&dmsgPort, "dport", "d", scriptExecUint("${DMSGPORT:-80}"), "dmsg port to serve")
uiCmd.Flags().Uint16VarP(&dmsgPort, "dport", "d", scriptExecUint16("${DMSGPORT:-80}"), "dmsg port to serve")
uiCmd.Flags().IntVarP(&dmsgSess, "dsess", "e", scriptExecInt("${DMSGSESSIONS:-1}"), "dmsg sessions")
msg := "add whitelist keys, comma separated to permit POST of reward transaction to be broadcast"
if scriptExecArray("${REWARDPKS[@]}") != "" {
Expand Down Expand Up @@ -95,7 +95,7 @@ var (
runTime time.Duration
sk cipher.SecKey
dmsgDisc string
dmsgPort uint
dmsgPort uint16
dmsgSess int
wl string
wlkeys []cipher.PubKey
Expand Down Expand Up @@ -1506,6 +1506,47 @@ func scriptExecUint(s string) uint {
return uint(0)
}

func scriptExecUint16(s string) uint16 {
if runtime.GOOS == "windows" {
var variable string
if strings.Contains(s, ":-") {
parts := strings.SplitN(s, ":-", 2)
variable = parts[0] + "}"
} else {
variable = s
}
out, err := script.Exec(fmt.Sprintf(`powershell -c '$SKYENV = "%s"; if ($SKYENV -ne "" -and (Test-Path $SKYENV)) { . $SKYENV }; echo %s"`, skyenvfile, variable)).String()
if err == nil {
if (out == "") || (out == variable) {
return 0
}
i, err := strconv.Atoi(strings.TrimSpace(strings.TrimRight(out, "\n")))
if err == nil {
if i >= 0 && i <= 65535 {
return uint16(i) //nolint
}
return 0
}
return 0
}
return 0
}
z, err := script.Exec(fmt.Sprintf(`bash -c 'SKYENV=%s ; if [[ $SKYENV != "" ]] && [[ -f $SKYENV ]] ; then source $SKYENV ; fi ; printf "%s"'`, skyenvfile, s)).String()
if err == nil {
if z == "" {
return 0
}
i, err := strconv.Atoi(z)
if err == nil {
if i >= 0 && i <= 65535 {
return uint16(i) //nolint
}
return 0
}
}
return uint16(0)
}

func whitelistAuth(whitelistedPKs []cipher.PubKey) gin.HandlerFunc {
return func(c *gin.Context) {
// Get the remote PK.
Expand Down
4 changes: 2 additions & 2 deletions cmd/skywire-cli/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ var treeCmd = &cobra.Command{
SilenceUsage: true,
DisableSuggestions: true,
DisableFlagsInUseLine: true,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
// You can use a LeveledList here, for easy generation.
leveledList := pterm.LeveledList{}
leveledList = append(leveledList, pterm.LeveledListItem{Level: 0, Text: RootCmd.Use})
Expand Down Expand Up @@ -140,7 +140,7 @@ var docCmd = &cobra.Command{
SilenceUsage: true,
DisableSuggestions: true,
DisableFlagsInUseLine: true,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
fmt.Printf("\n# %s\n", "skywire-cli documentation")
fmt.Printf("\n%s\n", "skywire command line interface")

Expand Down
2 changes: 1 addition & 1 deletion cmd/skywire-cli/commands/survey/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ var surveyCmd = &cobra.Command{
DisableFlagsInUseLine: true,
Short: "system survey",
Long: "print the system survey",
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
if pkg {
confPath = visorconfig.SkywirePath + "/" + visorconfig.ConfigJSON
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/skywire-cli/commands/tp/tp.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ var rmTpCmd = &cobra.Command{
Short: "Remove transport(s) by id",
Long: "\n Remove transport(s) by id",
DisableFlagsInUseLine: true,
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
rpcClient, err := clirpc.Client(cmd.Flags())
if removeAll {
internal.Catch(cmd.Flags(), rpcClient.RemoveAllTransports())
Expand Down Expand Up @@ -439,7 +439,7 @@ var treeCmd = &cobra.Command{
Use: "tree",
Short: "tree map of transports on the skywire network",
Long: fmt.Sprintf("display a tree representation of transports from TPD\n\n%v/all-transports\n\nSet cache file location to \"\" to avoid using cache files", tpDiscURL),
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
if rootNode != "" {
err := rootnode.Set(rootNode)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/skywire-cli/commands/visor/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ var registerAppCmd = &cobra.Command{
Use: "register",
Short: "Register app",
Long: "\n Register app",
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
rpcClient, err := clirpc.Client(cmd.Flags())
if err != nil {
os.Exit(1)
Expand Down Expand Up @@ -175,7 +175,7 @@ var deregisterAppCmd = &cobra.Command{
Use: "deregister",
Short: "Deregister app",
Long: "\n Deregister app",
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
rpcClient, err := clirpc.Client(cmd.Flags())
if err != nil {
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion cmd/skywire-cli/commands/visor/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var testCmd = &cobra.Command{
Use: "test",
Short: "Test the visor with public visors on network",
Long: "\n Creates a route with public visors as a hop and returns latency on the conn",
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
pingConfig := visor.PingConfig{Tries: tries, PcktSize: pcktSize, PubVisCount: pubVisCount}
rpcClient, err := clirpc.Client(cmd.Flags())
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions cmd/skywire-cli/commands/visor/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func init() {
var startCmd = &cobra.Command{
Use: "start",
Short: "start visor",
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
var output string
var err error
if !sourcerun {
Expand Down Expand Up @@ -71,7 +71,7 @@ var reloadCmd = &cobra.Command{
Use: "reload",
Short: "reload visor",
Hidden: true,
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
rpcClient, err := clirpc.Client(cmd.Flags())
if err != nil {
os.Exit(1)
Expand All @@ -97,7 +97,7 @@ var shutdownCmd = &cobra.Command{
Use: "halt",
Short: "Stop a running visor",
Long: "\n Stop a running visor",
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
rpcClient, err := clirpc.Client(cmd.Flags())
if err != nil {
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion cmd/skywire-cli/commands/vpn/vvpn.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ var listCmd = &cobra.Command{
Use: "list",
Short: "List servers",
Long: fmt.Sprintf("List %v servers from service discovery\n%v/api/services?type=%v\n%v/api/services?type=%v&country=US\n\nSet cache file location to \"\" to avoid using cache files", serviceType, sdURL, serviceType, sdURL, serviceType),
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
sds := internal.GetData(cacheFileSD, sdURL+"/api/services?type="+serviceType, cacheFilesAge)
if rawData {
script.Echo(string(pretty.Color(pretty.Pretty([]byte(sds)), nil))).Stdout() //nolint
Expand Down
4 changes: 2 additions & 2 deletions cmd/skywire/skywire.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ var treeCmd = &cobra.Command{
SilenceUsage: true,
DisableSuggestions: true,
DisableFlagsInUseLine: true,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
// You can use a LeveledList here, for easy generation.
leveledList := pterm.LeveledList{}
leveledList = append(leveledList, pterm.LeveledListItem{Level: 0, Text: RootCmd.Use})
Expand Down Expand Up @@ -270,7 +270,7 @@ var docCmd = &cobra.Command{
SilenceUsage: true,
DisableSuggestions: true,
DisableFlagsInUseLine: true,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
fmt.Printf("\n# %s\n", "skywire documentation")
fmt.Printf("\n## %s\n", "subcommand tree")
fmt.Printf("\n%s\n", "A tree representation of the skywire subcommands")
Expand Down
Loading

0 comments on commit e82d056

Please sign in to comment.