-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #171 from mavimo/introduce-unused-check
introduce code checker and code cleanup
- Loading branch information
Showing
20 changed files
with
87 additions
and
287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,19 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"time" | ||
|
||
"github.com/Pallinder/go-randomdata" | ||
"github.com/hetznercloud/hcloud-go/hcloud" | ||
) | ||
|
||
var sshPassPhrases = make(map[string][]byte) | ||
|
||
func waitAction(ctx context.Context, client *hcloud.Client, action *hcloud.Action) (<-chan error, <-chan int) { | ||
errCh := make(chan error, 1) | ||
progressCh := make(chan int) | ||
|
||
go func() { | ||
defer close(errCh) | ||
defer close(progressCh) | ||
|
||
ticker := time.NewTicker(100 * time.Millisecond) | ||
|
||
sendProgress := func(p int) { | ||
select { | ||
case progressCh <- p: | ||
break | ||
default: | ||
break | ||
} | ||
} | ||
|
||
for { | ||
select { | ||
case <-ctx.Done(): | ||
errCh <- ctx.Err() | ||
return | ||
case <-ticker.C: | ||
break | ||
} | ||
|
||
action, _, err := client.Action.GetByID(ctx, action.ID) | ||
if err != nil { | ||
errCh <- ctx.Err() | ||
return | ||
} | ||
|
||
switch action.Status { | ||
case hcloud.ActionStatusRunning: | ||
sendProgress(action.Progress) | ||
break | ||
case hcloud.ActionStatusSuccess: | ||
sendProgress(100) | ||
errCh <- nil | ||
return | ||
case hcloud.ActionStatusError: | ||
errCh <- action.Error() | ||
return | ||
} | ||
} | ||
}() | ||
|
||
return errCh, progressCh | ||
} | ||
|
||
func randomName() string { | ||
return fmt.Sprintf("%s-%s%s", randomdata.Adjective(), randomdata.Noun(), randomdata.Adjective()) | ||
} | ||
|
||
//Index find the index of an element int the array | ||
func Index(vs []string, t string) int { | ||
for i, v := range vs { | ||
if v == t { | ||
return i | ||
} | ||
} | ||
return -1 | ||
} | ||
|
||
//Include indicate if a string is in the strinc array | ||
func Include(vs []string, t string) bool { | ||
return Index(vs, t) >= 0 | ||
} | ||
|
||
//FatalOnError is an helper function to transform error to fatl | ||
func FatalOnError(err error) { | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func waitOrError(tc chan bool, ec chan error, numProcPtr *int) error { | ||
numProcs := *numProcPtr | ||
for numProcs > 0 { | ||
select { | ||
case err := <-ec: | ||
return err | ||
case <-tc: | ||
numProcs-- | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.