Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ goc build .
# Build the current binary with cover variables injected, and set the registry center to http://127.0.0.1:7777.
goc build --center=http://127.0.0.1:7777

# Build the current binary with cover variables injected, and set the registry name.
goc build --service=srv1

# Build the current binary with cover variables injected, and redirect output to /to/this/path.
goc build --output /to/this/path

Expand Down Expand Up @@ -77,6 +80,7 @@ func runBuild(args []string, wd string) {
Target: gocBuild.TmpDir,
Mode: coverMode.String(),
AgentPort: agentPort.String(),
Service: service,
Center: center,
Singleton: singleton,
IsMod: gocBuild.IsMod,
Expand Down
2 changes: 2 additions & 0 deletions cmd/commonflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
var (
target string
center string
service string
agentPort AgentPort
debugGoc bool
debugInCISyncFile string
Expand Down Expand Up @@ -60,6 +61,7 @@ func addCommonFlags(cmdset *pflag.FlagSet) {

func addBuildFlags(cmdset *pflag.FlagSet) {
addCommonFlags(cmdset)
cmdset.StringVar(&service, "service", "", "register service name. if not provided, using the binary file name")
// bind to viper
viper.BindPFlags(cmdset)
}
Expand Down
1 change: 1 addition & 0 deletions cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func runInstall(args []string, wd string) {
Target: gocBuild.TmpDir,
Mode: coverMode.String(),
AgentPort: agentPort.String(),
Service: service,
Center: center,
Singleton: singleton,
IsMod: gocBuild.IsMod,
Expand Down
1 change: 1 addition & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ goc run . [--buildflags] [--exec] [--arguments]
Center: gocServer,
Singleton: singleton,
AgentPort: "",
Service: service,
IsMod: gocBuild.IsMod,
ModRootPath: gocBuild.ModRootPath,
OneMainPackage: true, // go run is similar with go build, build only one main package
Expand Down
3 changes: 3 additions & 0 deletions pkg/cover/cover.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type TestCover struct {
Mode string
AgentPort string
Center string // cover profile host center
Service string
Singleton bool
MainPkgCover *PackageCover
DepsCover []*PackageCover
Expand Down Expand Up @@ -139,6 +140,7 @@ type CoverInfo struct {
Args string
Mode string
AgentPort string
Service string
Center string
Singleton bool
}
Expand Down Expand Up @@ -190,6 +192,7 @@ func Execute(coverInfo *CoverInfo) error {
Mode: mode,
AgentPort: agentPort,
Center: center,
Service: coverInfo.Service,
Singleton: singleton,
MainPkgCover: mainCover,
GlobalCoverVarImportPath: globalCoverVarImportPath,
Expand Down
4 changes: 4 additions & 0 deletions pkg/cover/instrument.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ func registerHandlers() {

func registerSelf(address string) ([]byte, error) {
selfName := filepath.Base(os.Args[0])
serviceName := {{.Service | printf "%q"}}
if serviceName != "" {
selfName = serviceName
}
req, err := http.NewRequest("POST", fmt.Sprintf("%s/v1/cover/register?name=%s&address=%s", {{.Center | printf "%q"}}, selfName, address), nil)
if err != nil {
log.Fatalf("http.NewRequest failed: %v", err)
Expand Down