Questions tagged [gofmt]

Go command. Gofmt formats Go programs. It uses tabs (width = 8) for indentation and blanks for alignment.

Go command. Gofmt formats Go programs. It uses tabs (width = 8) for indentation and blanks for alignment.

Without an explicit path, it processes the standard input. Given a file, it operates on that file; given a directory, it operates on all .go files in that directory, recursively. (Files starting with a period are ignored.) By default, gofmt prints the reformatted sources to standard output.

Useful links

59 questions
0
votes
1 answer

Vim normal mode shows tabs as 1 char wide, not aligned to left margin

This is the leftmost my cursor goes in normal mode. This is how it looks in insert mode. I have the following filetype settings au BufNewFile,BufRead *.py \ set tabstop=4 | \ set softtabstop=4 | \ set shiftwidth=4 | \ set…
Ishan Khare
  • 1,745
  • 4
  • 28
  • 59
0
votes
3 answers

gofmt preserving of newlines

When formatting go source code with gofmt, it preserves the newlines so you can group items together. I'm interested on how this is actually implemented. I tried looking at the source code in the github repo golang/go, but couldn't find it…
Seneca
  • 2,392
  • 2
  • 18
  • 33
0
votes
2 answers

Why does "fmt.Sprintf("%v,", lines[i])" put the comma on new line?

This is the full code: files, _ := ioutil.ReadDir("files") for _, f := range files { input, err := ioutil.ReadFile("files/" + f.Name()) lines := strings.Split(string(input), "\n") for i, _ := range lines { lines[i] =…
fisker
  • 979
  • 4
  • 18
  • 28
0
votes
0 answers

Gosublime indent not working (might be there is an issue with gofmt in gosublime)

I have pasted two images here Here you can see proper indentation in Gedit text editor Now, in Sublime3 it is not proper I'm using GoSublime and my settings are: { "env": { "GOROOT": "/usr/local/go", "GOPATH":"$HOME/go-work" …
rsudip90
  • 799
  • 1
  • 7
  • 24
0
votes
1 answer

disable gofmt in vim-plug in vim ide

How can i disable gofmt in vim-plug ide for vim? Hello, I'm using vim-plug as my vim based IDE for golang. I've a very specific query. I don't want gofmt to do any unnecessary formatting for my code. I raised an issue with vim-plug on github but I…
sameer oak
  • 23
  • 3
-1
votes
1 answer

Regex match of =~ returns wrong result when starts with .*

package main import "fmt" import "regexp" func main() { var sep = "=~" var filter = "exported_pod=~.*grafana.*" matched, _ := regexp.MatchString(sep+`\b`, filter) fmt.Println(matched) } In the above snippet, I'm trying to return…
zubug55
  • 729
  • 7
  • 27
-1
votes
1 answer

Run go fmt ./... got different behaviours on different OS

When I run go fmt ./... under the root directory of the project in my vscode I got different formatting results on different OS: Windows import ( "github.com/abc" "gotest.tools/assert" "testing" ) MacOS import…
User3301
  • 95
  • 3
  • 8
-1
votes
1 answer

How to suppress date when printing elapsed time

I have the following Go code used to capture elapsed time: import ( "time" ) start := time.Now() ... end := time.Since(start) log.Printf("Elapsed Time: %s", end) The output of which is: 2019/10/26 13:22:53 Elapsed Time : 41.867µs I would like…
HMLDude
  • 1,547
  • 7
  • 27
  • 47
-1
votes
1 answer

Can gofmt accommodate local coding standard preferences?

I love the role that gofmt has in Go programming. We would rather, though, that the following: func somefunc( a *sometype, // Explanation of a b int, // Explanation of b longName float64, // Explanation of longName ) { ... be able to be…
Scott Deerwester
  • 3,503
  • 4
  • 33
  • 56
-2
votes
1 answer

How to index parameters when formatting a string in Go

Let's say I have a string "Hello %s. How are you %s" and I want to put the same string in both of %s. The obvious option is to use: fmt.Printf("Hello %s. How are you %s", "KK", "KK") // returns "Hello KK. How are you KK" is there a way to index the…
unitSphere
  • 241
  • 3
  • 17
-2
votes
2 answers

how print variable values in Go with fmt.Printl?

I have the below code snippet: x_variable := 12311 fmt.Println("message", "X variable has the value '+x_variable+' printed in the screen now") How can I make that work? I've tried that in the Go playground but couldn't figure it out how to print…
jimmy
  • 457
  • 5
  • 20
-2
votes
1 answer

"file is not gofmted" in go report card

I have a Go project, where I wanted to generate a Go report card (https://goreportcard.com/) One of the things that this report card is that it runs gofmt -s On all files. My repo contains around 25 Go files, the only flag that is raised is this…
crypto_confuse
  • 463
  • 1
  • 4
  • 9
-3
votes
1 answer

Fixing go imports to relative instead of absolute path

Is there a tool that could change the imports across my package from absolute path to a relative path. Currently my import for package bar look like this : import FOO_common/server/src/foo/bar I want to convert this to import foo/bar Is there a…
nitimalh
  • 919
  • 10
  • 26
-6
votes
1 answer

fmt.Printf("%f\n",x) rounds a Float64 to Float32, but fmt.Println(x) doesn't

I was working on some tests with dictionaries, to do this I print out the Float64 values I want from a database in a format to copy and paste them into my test struct array, but when my tests failed I noticed that the values differ, but only by…
Devyzr
  • 299
  • 5
  • 13
1 2 3
4