Skip to content

Commit

Permalink
🧹 use go/format for code formatting of builtin providers
Browse files Browse the repository at this point in the history
Signed-off-by: Dominik Richter <[email protected]>
  • Loading branch information
arlimus committed Sep 17, 2023
1 parent 436aabf commit 7427c3f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ providers/proto:
.PHONY: providers/config
providers/config:
go run ./providers-sdk/v1/util/configure/configure.go -f providers.yaml -o providers/builtin_dev.go
gofmt -w providers/builtin.go

.PHONY: providers/lr
providers/lr:
Expand Down
11 changes: 8 additions & 3 deletions providers-sdk/v1/util/configure/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package main

import (
"fmt"
"go/format"
"os"
"os/exec"
"regexp"
Expand Down Expand Up @@ -47,8 +48,11 @@ var rootCmd = &cobra.Command{
}

builtinGo, err := genBuiltinGo(conf)
if err != nil {
log.Fatal().Err(err).Str("path", confPath).Msg("failed to generate builtin go")
}

if err = os.WriteFile(outPath, []byte(builtinGo), 0o644); err != nil {
if err = os.WriteFile(outPath, builtinGo, 0o644); err != nil {
log.Fatal().Err(err).Str("path", outPath).Msg("failed to write output")
}
log.Info().Str("path", outPath).Strs("providers", conf.Builtin).Msg("(1/3) configured builtin providers")
Expand All @@ -61,7 +65,7 @@ var rootCmd = &cobra.Command{
},
}

func genBuiltinGo(conf ProvidersConf) (string, error) {
func genBuiltinGo(conf ProvidersConf) ([]byte, error) {
var imports string
var infos string
var configs string
Expand All @@ -87,7 +91,8 @@ func genBuiltinGo(conf ProvidersConf) (string, error) {
`, provider, provider, provider, provider, provider, provider, provider)
}

return fmt.Sprintf(template, imports, infos, configs), nil
res := fmt.Sprintf(template, imports, infos, configs)
return format.Source([]byte(res))
}

const template = `// Copyright (c) Mondoo, Inc.
Expand Down
1 change: 1 addition & 0 deletions providers/builtin_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ func init() {
// },
// Config: &osconf.Config,
// }

}

0 comments on commit 7427c3f

Please sign in to comment.