mirror of https://github.com/grafana/grafana
Codegen: format golang code from cue (#105352)
parent
a26d907dae
commit
f0d6375b3b
@ -0,0 +1,29 @@ |
||||
package codegen |
||||
|
||||
import ( |
||||
"go/format" |
||||
"path/filepath" |
||||
|
||||
"golang.org/x/tools/imports" |
||||
|
||||
"github.com/grafana/codejen" |
||||
) |
||||
|
||||
// GoFormat applies go format to each go file
|
||||
func GoFormat() codejen.FileMapper { |
||||
return func(f codejen.File) (codejen.File, error) { |
||||
if filepath.Ext(f.RelativePath) != ".go" { |
||||
return f, nil |
||||
} |
||||
|
||||
formatted, err := format.Source(f.Data) |
||||
if err != nil { |
||||
return f, err |
||||
} |
||||
|
||||
f.Data, err = imports.Process("", formatted, &imports.Options{ |
||||
Comments: true, |
||||
}) |
||||
return f, err |
||||
} |
||||
} |
Loading…
Reference in new issue