https://github.com/bbrodriges/bundle
Bundle merges multiple Go source files into single one
https://github.com/bbrodriges/bundle
bundling golang source-code
Last synced: 3 months ago
JSON representation
Bundle merges multiple Go source files into single one
- Host: GitHub
- URL: https://github.com/bbrodriges/bundle
- Owner: bbrodriges
- License: mit
- Created: 2018-08-20T05:54:04.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-08-23T07:12:33.000Z (almost 8 years ago)
- Last Synced: 2025-12-17T12:37:41.817Z (6 months ago)
- Topics: bundling, golang, source-code
- Language: Go
- Size: 8.79 KB
- Stars: 4
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bundle
Bundle merges multiple Go source files into single one.
# Install
```
go get -u github.com/bbrodriges/bundle
```
# Usage
As a separate command:
```
$ bundle --help
Usage: bundle -p [-d] pattern...
Available options:
-d Delete source files after bundling
-p string
Package name to be written into result file. Required
$ bundle -d -p main *_gen.go > bundle.go # bundle all autogenerated files in current folder
$ bundle -d -p main -o bundle.go user.msgp.go user.str.go # bundle only specific files
```
As a `go generate` flag:
```go
package types
//go:generate msgp -o=user.msgp.go -tests=false -io=false
//go:generate stringer -type=User -output=user.str.go -linecomment
//msgp:shim UserState as:string using:(UserState).String/UserStateFromString
//go:generate bundle -d -p=types -o=user_gen.go user.msgp.go user.str.go
type User struct {
Username string `msg:"username"`
Email string `msg:"email"`
State UserState `msg:"state"`
}
type UserState int
const (
Unknown UserState = iota -1 // UNKNOWN
Inactive // INACTIVE
Active // ACTIVE
Banned // BANNED
)
func UserStateFromString(s string) UserState {
switch s {
case "INACTIVE":
return Inactive
case "ACTIVE":
return Active
case "BANNED":
return Banned
}
return Unknown
}
```
The above code upon calling `go generate .` will:
1. create files called `user.msgp.go` and `user.str.go` with containing autogenerated code
2. bundle these two files into single `user_gen.go` and delete source files `user.msgp.go` and `user.str.go`
# Limitations
* bundle cannot handle definition conflicts (e.g. structs, functions, constants of the same names)
* bundle cannot handle import cycle conflicts
All it does is collects and strips out import declarations from every given source files AST and concats them into single file with helping comments.