Skip to content

Commit 621afd2

Browse files
authored
chore: update dependencies, go 1.16 and move command to cmd package
1 parent 326e5b5 commit 621afd2

File tree

11 files changed

+255
-171
lines changed

11 files changed

+255
-171
lines changed

.golangci.toml

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"wrapcheck",
4141
"noctx",
4242
"exhaustivestruct",
43+
"cyclop",
4344
]
4445

4546
[issues]

.semaphore/semaphore.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ global_job_config:
2727
# so it's not possible to use sem-version.
2828
# - sem-version go 1.14
2929
- curl -sSfL https://raw.githubusercontent.com/ldez/semgo/master/godownloader.sh | sudo sh -s -- -b "/usr/local/bin"
30-
- sudo semgo go1.15
30+
- sudo semgo go1.16
3131
- export "GOPATH=$(go env GOPATH)"
3232
- export "SEMAPHORE_GIT_DIR=${GOPATH}/src/github.com/traefik/${SEMAPHORE_PROJECT_NAME}"
3333
- export "PATH=${GOPATH}/bin:${PATH}"
3434
- mkdir -vp "${SEMAPHORE_GIT_DIR}" "${GOPATH}/bin"
3535
- export GOPROXY=https://gomod.traefiklabs.tech,https://proxy.golang.org,direct
3636
- cat /home/semaphore/datas/traefiker-keyfile.json | docker login -u _json_key --password-stdin https://gcr.io
3737
- echo "${DOCKERHUB_PASSWORD}" | docker login -u "${DOCKERHUB_USERNAME}" --password-stdin
38-
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "${GOPATH}/bin" v1.35.2
38+
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "${GOPATH}/bin" v1.37.1
3939
- curl -sfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | bash -s -- -b "${GOPATH}/bin"
4040
- checkout
4141
- cache restore "mod-${SEMAPHORE_PROJECT_NAME}-${SEMAPHORE_GIT_BRANCH}-$(checksum go.mod),mod-${SEMAPHORE_PROJECT_NAME}-$(checksum go.mod),mod-${SEMAPHORE_PROJECT_NAME}"

cmd/run/command.go

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package run
2+
3+
import "github.com/urfave/cli/v2"
4+
5+
// Command creates the run command.
6+
func Command() *cli.Command {
7+
cmd := &cli.Command{
8+
Name: "run",
9+
Usage: "Run Piceus",
10+
Description: "Launch application piceus",
11+
Flags: []cli.Flag{
12+
&cli.StringFlag{
13+
Name: "github-token",
14+
Usage: "GitHub Token.",
15+
EnvVars: []string{"GITHUB_TOKEN"},
16+
Required: true,
17+
},
18+
&cli.StringFlag{
19+
Name: "services-access-token",
20+
Usage: "Pilot Services Access Token",
21+
EnvVars: []string{"PILOT_SERVICES_ACCESS_TOKEN"},
22+
Required: true,
23+
},
24+
&cli.StringFlag{
25+
Name: "plugin-url",
26+
Usage: "Plugin Service URL",
27+
EnvVars: []string{"PILOT_PLUGIN_URL"},
28+
Required: true,
29+
},
30+
},
31+
Action: func(cliCtx *cli.Context) error {
32+
cfg := buildConfig(cliCtx)
33+
34+
return run(cliCtx.Context, cfg)
35+
},
36+
}
37+
38+
cmd.Flags = append(cmd.Flags, tracingFlags()...)
39+
40+
return cmd
41+
}
42+
43+
func tracingFlags() []cli.Flag {
44+
return []cli.Flag{
45+
&cli.StringFlag{
46+
Name: "tracing-endpoint",
47+
Usage: "Endpoint to send traces",
48+
EnvVars: []string{"TRACING_ENDPOINT"},
49+
Value: "https://collector.infra.traefiklabs.tech",
50+
Required: false,
51+
},
52+
&cli.StringFlag{
53+
Name: "tracing-username",
54+
Usage: "Username to connect to Jaeger",
55+
EnvVars: []string{"TRACING_USERNAME"},
56+
Value: "jaeger",
57+
Required: false,
58+
},
59+
&cli.StringFlag{
60+
Name: "tracing-password",
61+
Usage: "Password to connect to Jaeger",
62+
EnvVars: []string{"TRACING_PASSWORD"},
63+
Value: "jaeger",
64+
Required: false,
65+
},
66+
&cli.Float64Flag{
67+
Name: "tracing-probability",
68+
Usage: "Probability to send traces.",
69+
EnvVars: []string{"TRACING_PROBABILITY"},
70+
Value: 0,
71+
Required: false,
72+
},
73+
}
74+
}

cmd/run/config.go

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package run
2+
3+
import "github.com/urfave/cli/v2"
4+
5+
// Pilot holds the pilot configuration.
6+
type Pilot struct {
7+
GithubToken string
8+
ServicesAccessToken string
9+
PluginURL string
10+
}
11+
12+
// Tracing holds the tracing configuration.
13+
type Tracing struct {
14+
Endpoint string
15+
Username string
16+
Password string
17+
Probability float64
18+
}
19+
20+
// Config represents the configuration for the run command.
21+
type Config struct {
22+
Pilot Pilot
23+
Tracing Tracing
24+
}
25+
26+
func buildConfig(cliCtx *cli.Context) Config {
27+
return Config{
28+
Pilot: Pilot{
29+
GithubToken: cliCtx.String("github-token"),
30+
ServicesAccessToken: cliCtx.String("services-access-token"),
31+
PluginURL: cliCtx.String("plugin-url"),
32+
},
33+
Tracing: Tracing{
34+
Endpoint: cliCtx.String("tracing-endpoint"),
35+
Username: cliCtx.String("tracing-username"),
36+
Password: cliCtx.String("tracing-password"),
37+
Probability: cliCtx.Float64("tracing-probability"),
38+
},
39+
}
40+
}

cmd/run/run.go

+6-10
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,25 @@ import (
1111
"github.com/traefik/piceus/pkg/core"
1212
"github.com/traefik/piceus/pkg/sources"
1313
"github.com/traefik/piceus/pkg/tracer"
14-
"github.com/urfave/cli/v2"
1514
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
1615
"golang.org/x/oauth2"
1716
)
1817

19-
// Run executes Piceus scrapper.
20-
func Run(c *cli.Context) error {
21-
ctx := context.Background()
22-
23-
exporter, err := tracer.NewJaegerExporter(c.String("tracing-endpoint"), c.String("tracing-username"), c.String("tracing-password"))
18+
func run(ctx context.Context, cfg Config) error {
19+
exporter, err := tracer.NewJaegerExporter(cfg.Tracing.Endpoint, cfg.Tracing.Username, cfg.Tracing.Password)
2420
if err != nil {
2521
log.Error().Err(err).Msg("Unable to configure new exporter.")
2622
return err
2723
}
2824
defer exporter.Flush()
2925

30-
bsp := tracer.Setup(exporter, c.Float64("tracing-probability"))
31-
defer bsp.Shutdown()
26+
bsp := tracer.Setup(exporter, cfg.Tracing.Probability)
27+
defer func() { _ = bsp.Shutdown(ctx) }()
3228

33-
ghClient := newGitHubClient(ctx, c.String("github-token"))
29+
ghClient := newGitHubClient(ctx, cfg.Pilot.GithubToken)
3430
gpClient := goproxy.NewClient("")
3531

36-
pgClient := plugin.New(c.String("plugin-url"), c.String("services-access-token"))
32+
pgClient := plugin.New(cfg.Pilot.PluginURL, cfg.Pilot.ServicesAccessToken)
3733

3834
var srcs core.Sources
3935
if _, ok := os.LookupEnv(core.PrivateModeEnv); ok {

go.mod

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
module github.com/traefik/piceus
22

3-
go 1.15
3+
go 1.16
44

55
require (
6-
github.com/google/go-cmp v0.5.2
6+
github.com/google/go-cmp v0.5.4
77
github.com/google/go-github/v32 v32.1.0
88
github.com/ldez/grignotin v0.4.1
9-
github.com/mitchellh/mapstructure v1.3.3
9+
github.com/mitchellh/mapstructure v1.4.1
1010
github.com/pelletier/go-toml v1.8.1
1111
github.com/rs/zerolog v1.20.0
12-
github.com/stretchr/testify v1.6.1
13-
github.com/traefik/yaegi v0.9.12
12+
github.com/stretchr/testify v1.7.0
13+
github.com/traefik/yaegi v0.9.14
1414
github.com/urfave/cli/v2 v2.3.0
15-
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.13.0
16-
go.opentelemetry.io/otel v0.13.0
17-
go.opentelemetry.io/otel/exporters/trace/jaeger v0.13.0
18-
go.opentelemetry.io/otel/sdk v0.13.0
19-
golang.org/x/mod v0.3.0
20-
golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43
21-
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776
15+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.17.0
16+
go.opentelemetry.io/otel v0.17.0
17+
go.opentelemetry.io/otel/exporters/trace/jaeger v0.17.0
18+
go.opentelemetry.io/otel/sdk v0.17.0
19+
go.opentelemetry.io/otel/trace v0.17.0
20+
golang.org/x/mod v0.4.1
21+
golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93
22+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
2223
)

0 commit comments

Comments
 (0)