Skip to content

Commit

Permalink
Replace gofmt linter by gofumpt
Browse files Browse the repository at this point in the history
  • Loading branch information
dangra committed Aug 11, 2022
1 parent 2c81a64 commit 2c9ca3f
Show file tree
Hide file tree
Showing 105 changed files with 521 additions and 482 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ issues:
linters:
disable-all: true
enable:
- gofmt
- gofumpt
- deadcode
# - errcheck
- goimports
Expand Down
1 change: 0 additions & 1 deletion agent/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@ func (c *Client) WaitForTunnel(parent context.Context, slug string) (err error)

// WaitForDNS waits for a Fly host internal DNS entry to register
func (c *Client) WaitForDNS(parent context.Context, dialer Dialer, slug string, host string) (err error) {

io := iostreams.FromContext(parent)
io.StartProgressIndicatorMsg(fmt.Sprintf("Waiting for host %s", host))
ctx, cancel := context.WithTimeout(parent, 4*time.Minute)
Expand Down
5 changes: 1 addition & 4 deletions agent/server/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@ func (s *session) ping(_ context.Context, args ...string) {
})
}

var (
errMalformedEstablish = errors.New("malformed establish command")
)
var errMalformedEstablish = errors.New("malformed establish command")

func (s *session) doEstablish(ctx context.Context, recycle bool, args ...string) {
if !s.exactArgs(1, args, errMalformedEstablish) {
Expand Down Expand Up @@ -389,7 +387,6 @@ func (s *session) connect(ctx context.Context, args ...string) {
}

func (s *session) ping6(ctx context.Context, args ...string) {

// As with "dial", "ping6" handles an agent command and then
// repurposes the agent connection as a transport.

Expand Down
2 changes: 1 addition & 1 deletion agent/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func createLogFile() (path string, err error) {
func setupLogDirectory() (dir string, err error) {
dir = filepath.Join(flyctl.ConfigDir(), "agent-logs")

if err = os.MkdirAll(dir, 0700); err != nil {
if err = os.MkdirAll(dir, 0o700); err != nil {
err = fmt.Errorf("failed creating agent log directory at %s: %w", dir, err)

return
Expand Down
5 changes: 1 addition & 4 deletions cmd/autoscaling.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func newAutoscaleCommand(client *client.Client) *Command {
autoscaleStrings := docstrings.Get("autoscale")

cmd := BuildCommandKS(nil, nil, autoscaleStrings, client, requireSession, requireAppName)
//cmd.Deprecated = "use `flyctl scale` instead"
// cmd.Deprecated = "use `flyctl scale` instead"

disableCmdStrings := docstrings.Get("autoscale.disable")
disableCmd := BuildCommand(cmd, runDisableAutoscaling, disableCmdStrings.Usage, disableCmdStrings.Short, disableCmdStrings.Long, client, requireSession, requireAppName)
Expand Down Expand Up @@ -100,7 +100,6 @@ func actualScale(cmdCtx *cmdctx.CmdContext, balanceRegions bool, setParamsOnly b

if found {
minint64val, err := strconv.ParseInt(minval, 10, 64)

if err != nil {
return errors.New("could not parse min count value")
}
Expand All @@ -113,7 +112,6 @@ func actualScale(cmdCtx *cmdctx.CmdContext, balanceRegions bool, setParamsOnly b

if found {
maxint64val, err := strconv.ParseInt(maxval, 10, 64)

if err != nil {
return errors.New("could not parse max count value")
}
Expand Down Expand Up @@ -158,7 +156,6 @@ func runAutoscalingShow(cmdCtx *cmdctx.CmdContext) error {
}

func printScaleConfig(cmdCtx *cmdctx.CmdContext, cfg *api.AutoscalingConfig) {

asJSON := cmdCtx.OutputJSON()

if asJSON {
Expand Down
2 changes: 0 additions & 2 deletions cmd/certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
)

func getAlternateHostname(hostname string) string {

if strings.Split(hostname, ".")[0] == "www" {
return strings.Replace(hostname, "www.", "", 1)
} else {
Expand Down Expand Up @@ -85,7 +84,6 @@ func runCertShow(commandContext *cmdctx.CmdContext) error {
commandContext.Statusf("certs", cmdctx.STITLE, "The certificate for %s has not been issued yet.\n\n", hostname)
printCertificate(commandContext, cert)
return reportNextStepCert(commandContext, hostname, cert, hostcheck)

}

func runCertCheck(commandContext *cmdctx.CmdContext) error {
Expand Down
2 changes: 0 additions & 2 deletions cmd/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ func setSlackChecksHandler(cmdCtx *cmdctx.CmdContext, org *api.Organization, nam
// }

handler, err := cmdCtx.Client.API().SetSlackHealthCheckHandler(ctx, input)

if err != nil {
return err
}
Expand Down Expand Up @@ -205,7 +204,6 @@ func setPagerDutyChecksHandler(cmdCtx *cmdctx.CmdContext, org *api.Organization,
}

handler, err := cmdCtx.Client.API().SetPagerdutyHealthCheckHandler(ctx, input)

if err != nil {
return err
}
Expand Down
1 change: 0 additions & 1 deletion cmd/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ func BuildCommand(parent *Command, fn RunFn, usageText string, shortHelpText str
Short: shortHelpText,
Long: longHelpText,
}, client, options...)

}

const defaultConfigFilePath = "./fly.toml"
Expand Down
14 changes: 6 additions & 8 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
)

func newConfigCommand(client *client.Client) *Command {

configStrings := docstrings.Get("config")

cmd := BuildCommandKS(nil, nil, configStrings, client, requireSession, requireAppName)
Expand Down Expand Up @@ -45,9 +44,9 @@ func runDisplayConfig(cmdCtx *cmdctx.CmdContext) error {
return err
}

//encoder := json.NewEncoder(os.Stdout)
//encoder.SetIndent("", " ")
//encoder.Encode(cfg.Definition)
// encoder := json.NewEncoder(os.Stdout)
// encoder.SetIndent("", " ")
// encoder.Encode(cfg.Definition)
cmdCtx.WriteJSON(cfg.Definition)
return nil
}
Expand All @@ -56,7 +55,6 @@ func runSaveConfig(cmdCtx *cmdctx.CmdContext) error {
ctx := cmdCtx.Command.Context()

configfilename, err := flyctl.ResolveConfigFileFromPath(cmdCtx.WorkingDir)

if err != nil {
return err
}
Expand Down Expand Up @@ -121,8 +119,9 @@ func runEnvConfig(cmdCtx *cmdctx.CmdContext) error {
}

if len(secrets) > 0 {
err = cmdCtx.Frender(cmdctx.PresenterOption{Presentable: &presenters.Secrets{Secrets: secrets},
Title: "Secrets",
err = cmdCtx.Frender(cmdctx.PresenterOption{
Presentable: &presenters.Secrets{Secrets: secrets},
Title: "Secrets",
})
if err != nil {
return err
Expand Down Expand Up @@ -160,7 +159,6 @@ func printAppConfigErrors(cfg api.AppConfig) {
}

func writeAppConfig(path string, appConfig *flyctl.AppConfig) error {

if err := appConfig.WriteToFile(path); err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ func runRecordsExport(cmdCtx *cmdctx.CmdContext) error {
if len(cmdCtx.Args) == 1 {
fmt.Println(records)
} else {
var filename = cmdCtx.Args[1]
filename := cmdCtx.Args[1]

_, err := os.Stat(filename)
if err == nil {
return fmt.Errorf("File %s already exists", filename)
}

err = ioutil.WriteFile(filename, []byte(records), 0644)
err = ioutil.WriteFile(filename, []byte(records), 0o644)
if err != nil {
return err
}
Expand Down
19 changes: 7 additions & 12 deletions cmd/launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ func newLaunchCommand(client *client.Client) *Command {
launchCmd.AddStringFlag(StringFlagOpts{
Name: "path",
Description: `path to app code and where a fly.toml file will be saved.`,
Default: "."},
Default: ".",
},
)
launchCmd.AddStringFlag(StringFlagOpts{
Name: "org",
Expand Down Expand Up @@ -138,7 +139,7 @@ func runLaunch(cmdCtx *cmdctx.CmdContext) error {

fmt.Println("Creating app in", dir)

var srcInfo = new(scanner.SourceInfo)
srcInfo := new(scanner.SourceInfo)

if img := cmdCtx.Config.GetString("image"); img != "" {
fmt.Println("Using image", img)
Expand Down Expand Up @@ -201,14 +202,14 @@ func runLaunch(cmdCtx *cmdctx.CmdContext) error {
continue
}

if err := os.MkdirAll(filepath.Dir(path), 0700); err != nil {
if err := os.MkdirAll(filepath.Dir(path), 0o700); err != nil {
return err
}

perms := 0600
perms := 0o600

if strings.Contains(string(f.Contents), "#!") {
perms = 0700
perms = 0o700
}

if err := os.WriteFile(path, f.Contents, fs.FileMode(perms)); err != nil {
Expand All @@ -225,7 +226,6 @@ func runLaunch(cmdCtx *cmdctx.CmdContext) error {
if appName == "" {
// Prompt the user for the app name
inputName, err := inputAppName("", true)

if err != nil {
return err
}
Expand Down Expand Up @@ -329,7 +329,6 @@ func runLaunch(cmdCtx *cmdctx.CmdContext) error {
if val, err = secret.Generate(); err != nil {
return fmt.Errorf("could not generate random string: %w", err)
}

} else if secret.Value != "" {
val = secret.Value
} else {
Expand All @@ -351,7 +350,6 @@ func runLaunch(cmdCtx *cmdctx.CmdContext) error {

if len(secrets) > 0 {
_, err := cmdCtx.Client.API().SetSecrets(ctx, cmdCtx.AppName, secrets)

if err != nil {
return err
}
Expand All @@ -361,11 +359,9 @@ func runLaunch(cmdCtx *cmdctx.CmdContext) error {

// If volumes are requested by the launch scanner, create them
if srcInfo != nil && len(srcInfo.Volumes) > 0 {

for _, vol := range srcInfo.Volumes {

appID, err := cmdCtx.Client.API().GetAppID(ctx, cmdCtx.AppName)

if err != nil {
return err
}
Expand Down Expand Up @@ -420,7 +416,6 @@ func runLaunch(cmdCtx *cmdctx.CmdContext) error {
if !cmdCtx.Config.GetBool("no-deploy") && !cmdCtx.Config.GetBool("now") && !srcInfo.SkipDatabase && confirm("Would you like to setup a Postgresql database now?") {

appID, err := cmdCtx.Client.API().GetAppID(ctx, cmdCtx.AppName)

if err != nil {
return err
}
Expand Down Expand Up @@ -532,7 +527,7 @@ func appendDockerfileAppendix(appendix []string) (err error) {

var f *os.File
// TODO: we don't flush
if f, err = os.OpenFile(dockerfilePath, os.O_APPEND|os.O_WRONLY, 0600); err != nil {
if f, err = os.OpenFile(dockerfilePath, os.O_APPEND|os.O_WRONLY, 0o600); err != nil {
return
}
defer func() {
Expand Down
7 changes: 4 additions & 3 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,15 @@ func runListApps(cmdCtx *cmdctx.CmdContext) error {
createdAt = apps[i].CurrentRelease.CreatedAt
}

filteredApps = append(filteredApps, appCondensed{ID: apps[i].ID,
filteredApps = append(filteredApps, appCondensed{
ID: apps[i].ID,
Name: apps[i].Name,
Status: apps[i].Status,
Deployed: apps[i].Deployed,
Hostname: apps[i].Hostname,
Organization: apps[i].Organization.Slug,
CreatedAt: createdAt})
CreatedAt: createdAt,
})
}
}

Expand Down Expand Up @@ -168,7 +170,6 @@ func runListOrgs(cmdCtx *cmdctx.CmdContext) error {
asJSON := cmdCtx.OutputJSON()

orgs, err := cmdCtx.Client.API().GetOrganizations(ctx)

if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,9 @@ func runApiCreatePostgresCluster(cmdCtx *cmdctx.CmdContext, org string, input *a

func runAttachPostgresCluster(cmdCtx *cmdctx.CmdContext) error {
// Minimum image version requirements
var (
MinPostgresHaVersion = "0.0.19"
)

MinPostgresHaVersion := "0.0.19"

ctx := cmdCtx.Command.Context()

postgresAppName := cmdCtx.Config.GetString("postgres-app")
Expand Down
1 change: 1 addition & 0 deletions cmd/presenters/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Environment struct {
func (p *Environment) APIStruct() interface{} {
return nil
}

func (p *Environment) FieldNames() []string {
return []string{"Name", "Value"}
}
Expand Down
2 changes: 0 additions & 2 deletions cmd/presenters/imageDetails.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ func (p *ImageDetails) APIStruct() interface{} {
}

func (p *ImageDetails) FieldNames() []string {

return []string{"Registry", "Repository", "Tag", "Version", "Digest"}
}

Expand All @@ -35,7 +34,6 @@ func (p *ImageDetails) Records() []map[string]string {
} else {
info["Version"] = "N/A"
}

}

out = append(out, info)
Expand Down
6 changes: 4 additions & 2 deletions cmd/presenters/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ func (lp *LogPresenter) FPrint(w io.Writer, asJSON bool, entry logs.LogEntry) {
lp.printEntry(w, asJSON, entry)
}

var newLineReplacer = strings.NewReplacer("\r\n", aurora.Faint("↩︎").String(), "\n", aurora.Faint("↩︎").String())
var newline = []byte("\n")
var (
newLineReplacer = strings.NewReplacer("\r\n", aurora.Faint("↩︎").String(), "\n", aurora.Faint("↩︎").String())
newline = []byte("\n")
)

func (lp *LogPresenter) printEntry(w io.Writer, asJSON bool, entry logs.LogEntry) {
if asJSON {
Expand Down
2 changes: 1 addition & 1 deletion cmd/presenters/presenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (p *Presenter) renderFieldList() error {
}

func (p *Presenter) renderJSON() error {
var data = p.Item.APIStruct()
data := p.Item.APIStruct()

if data == nil {
return fmt.Errorf("JSON output not available")
Expand Down
1 change: 1 addition & 0 deletions cmd/presenters/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Secrets struct {
func (p *Secrets) APIStruct() interface{} {
return nil
}

func (p *Secrets) FieldNames() []string {
return []string{"Name", "Digest", "Date"}
}
Expand Down
1 change: 0 additions & 1 deletion cmd/regions.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ func runBackupRegionsSet(cmdCtx *cmdctx.CmdContext) error {
}

func printRegions(ctx *cmdctx.CmdContext, regions []api.Region, backupRegions []api.Region) {

if ctx.OutputJSON() {

data := struct {
Expand Down
2 changes: 1 addition & 1 deletion cmd/scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func countMessage(counts []api.TaskGroupCount) string {

return msg

//return fmt.Sprintf("Count changed to %s\n", msg)
// return fmt.Sprintf("Count changed to %s\n", msg)
}

func maxPerRegionMessage(groups []api.ProcessGroup) string {
Expand Down

0 comments on commit 2c9ca3f

Please sign in to comment.