Skip to content

gominfmt makes the Go code more compact to aid further compression; revert with gofmt

License

Notifications You must be signed in to change notification settings

go-toolsmith/minformat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

158d7e0 · Jan 2, 2024

History

7 Commits
Dec 31, 2023
Jan 2, 2024
Oct 4, 2020
Oct 4, 2020
Dec 31, 2023
Dec 31, 2023
Dec 31, 2023
Dec 31, 2023
Dec 31, 2023

Repository files navigation

Go Report Card GoDoc

go/minformat

This package formats the Go source code in a way so it becomes more compact. It can be considered to be a minifier, although it doesn't make irreversible transformations by default (well, it does remove all comments).

The result can become readable again after running go/format, making this pipeline possible:

  1. Minify the code before transferring it over a network
  2. Send the (potentially further compressed) minified source code
  3. On the receiving side, run gofmt to get the canonical formatting

For (3) I would recommend using gofumpt.

Example

Suppose that we have this hello.go file:

package main

import (
	"fmt"
)

func main() {
	fmt.Println("Hello, playground")
}

It will be formatted into this:

package main;import("fmt");func main(){fmt.Println("Hello, playground")}

Depending on the file, it usually cuts 10-50% of the file size.