Remove comments from
Go code.
Remove comments from Go source code online. Preserves struct tags, raw string backticks, and gofmt-friendly formatting.
.go filesBefore and after
Real-world Go code on the left. The same code with every comment removed on the right.
// Package orders provides a repository for orders.
package orders
import (
"context"
"fmt"
)
// Order is a single customer order.
type Order struct {
ID string `json:"id"` // primary key
Total int `json:"total"` // amount in cents
}
/* Repository hides the storage layer. */
type Repository struct {
db DB // database handle
}
// FindByID returns the matching order.
func (r *Repository) FindByID(ctx context.Context, id string) (*Order, error) {
// Validate input
if id == "" {
return nil, fmt.Errorf("empty id") // caller error
}
return r.db.Query(ctx, id)
}package orders
import (
"context"
"fmt"
)
type Order struct {
ID string `json:"id"`
Total int `json:"total"`
}
type Repository struct {
db DB
}
func (r *Repository) FindByID(ctx context.Context, id string) (*Order, error) {
if id == "" {
return nil, fmt.Errorf("empty id")
}
return r.db.Query(ctx, id)
}Built for Go specifically.
Go code is famously simple, but generated code (`go generate`) and idiomatic doc comments above every exported identifier can still pile up. Stripping comments is useful before publishing a snippet, comparing two implementations, or shrinking a teaching example. Uncommenter handles Go's backtick raw strings without disturbing struct tags or any embedded `//` text.
- // line and /* */ block comments removed
- Raw string literals (backticks) preserved, including struct tags
- Build tags like //go:build kept (treated as directives, not regular comments, see FAQ)
- Auto-detected from .go files
Strip comments in 30 seconds.
- 1
Open the tool
Head to uncommenter.com/tool. Nothing to install. Nothing to sign up for.
- 2
Paste your Go code
Drop your .go file in, or paste code into the editor. Auto-detection picks up Go from the extension or file content.
- 3
Click 'Remove Comments'
The parser walks every character with a real state machine, strings, regex, and other context-sensitive parts are detected and left alone.
- 4
Copy or download
Grab the cleaned output. Your code never left your browser.
Go questions, answered.
Are struct tags safe?
+
Yes. Struct tags live inside backtick raw strings, which the parser treats as raw string literals. The // inside `json:"id"` is never misread as a comment.
What about //go:build directives?
+
Build tags use comment syntax, so by default Uncommenter removes them along with regular comments. If you need them kept, run the tool only on already-built source, or add them back via a build step.
Will it preserve doc comments?
+
Go uses // and /* */ for doc comments, there's no separate docstring syntax. Toggle 'preserve docstrings' off if you want everything gone.
Working in something else?
Plus 35+ more languages supported in the live tool , including HTML, YAML, Dockerfile, Terraform, Solidity, and more.
Try it on your Go code now.
Free forever. No signup. No upload. Runs entirely in your browser.
Open uncommenter