Skip to content

Commit fe99575

Browse files
author
Lukas Fischer
committed
#1894 Change golang structure
Standard or good golang project layout seems to be quite controversial, there is the [Standard Go Project Layout][1], which comes with an [extensive disussion][2] if this is encouraged or not. There are also [blogposts][3] by go team members and the official [Organizing a Go module][4] docs. The takeaway I got was that a cmd dir is good for the executables and a pkg dir is fine if it makes the repository structure better, and with all the helm and docker files this is certainly the case. [1]: https://github.com/golang-standards/project-layout [2]: golang-standards/project-layout#117 [3]: https://eli.thegreenplace.net/2019/simple-go-project-layout-with-modules/ [4]: https://go.dev/doc/modules/layout Signed-off-by: Lukas Fischer <lukas.fischer@iteratec.com>
1 parent 345a8b6 commit fe99575

File tree

15 files changed

+21
-27
lines changed

15 files changed

+21
-27
lines changed

auto-discovery/cloud-aws/.helmignore

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,12 @@ debug.env
3030

3131
*.tar
3232
auto-discovery-cloud-aws-config.yaml
33-
aws/
3433
bin/
35-
config/
34+
cmd/
3635
cover.out
3736
Dockerfile
3837
go.mod
3938
go.sum
4039
go.sum.license
41-
kubernetes/
42-
main_test.go
43-
main.go
4440
Makefile
45-
suite_test.go
41+
pkg/

auto-discovery/cloud-aws/Dockerfile

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@ COPY go.sum go.sum
1414
RUN go mod download
1515

1616
# Copy the go source
17-
COPY main.go main.go
18-
COPY aws/ aws/
19-
COPY config/ config/
20-
COPY kubernetes/ kubernetes/
17+
COPY cmd/ cmd/
18+
COPY pkg/ pkg/
2119

2220
# Build
23-
RUN CGO_ENABLED=0 go build -a -o service main.go
21+
RUN CGO_ENABLED=0 go build -a -o service cmd/service/main.go
2422

2523
# Use distroless as minimal base image to package the service binary
2624
# Refer to https://github.com/GoogleContainerTools/distroless for more details

auto-discovery/cloud-aws/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ helm-unit-tests:
7979

8080
.PHONY: build
8181
build: fmt vet ## Build service binary.
82-
go build -o bin/service main.go
82+
go build -o bin/service cmd/service/main.go
8383

8484
.PHONY: run
8585
run: fmt vet ## Run the service from your host.
86-
go run ./main.go --config auto-discovery-cloud-aws-config.yaml
86+
go run ./cmd/service/main.go --config auto-discovery-cloud-aws-config.yaml
8787

8888
.PHONY: docker-build
8989
docker-build: test ## Build docker image with the service.

auto-discovery/cloud-aws/main.go renamed to auto-discovery/cloud-aws/cmd/service/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import (
88
"flag"
99
"os"
1010

11-
"github.com/secureCodeBox/secureCodeBox/auto-discovery/cloud-aws/aws"
12-
"github.com/secureCodeBox/secureCodeBox/auto-discovery/cloud-aws/config"
13-
"github.com/secureCodeBox/secureCodeBox/auto-discovery/cloud-aws/kubernetes"
11+
"github.com/secureCodeBox/secureCodeBox/auto-discovery/cloud-aws/pkg/aws"
12+
"github.com/secureCodeBox/secureCodeBox/auto-discovery/cloud-aws/pkg/config"
13+
"github.com/secureCodeBox/secureCodeBox/auto-discovery/cloud-aws/pkg/kubernetes"
1414
ctrl "sigs.k8s.io/controller-runtime"
1515
"sigs.k8s.io/controller-runtime/pkg/log/zap"
1616
)

auto-discovery/cloud-aws/main_test.go renamed to auto-discovery/cloud-aws/cmd/service/main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
awssdk "github.com/aws/aws-sdk-go/aws"
1818
"github.com/aws/aws-sdk-go/service/ecs"
1919
"github.com/aws/aws-sdk-go/service/sqs"
20-
"github.com/secureCodeBox/secureCodeBox/auto-discovery/cloud-aws/aws"
20+
"github.com/secureCodeBox/secureCodeBox/auto-discovery/cloud-aws/pkg/aws"
2121
executionv1 "github.com/secureCodeBox/secureCodeBox/operator/apis/execution/v1"
2222
corev1 "k8s.io/api/core/v1"
2323
"k8s.io/apimachinery/pkg/api/errors"

auto-discovery/cloud-aws/suite_test.go renamed to auto-discovery/cloud-aws/cmd/service/suite_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import (
1616
"github.com/aws/aws-sdk-go/aws/request"
1717
"github.com/aws/aws-sdk-go/service/sqs"
1818
"github.com/go-logr/logr"
19-
"github.com/secureCodeBox/secureCodeBox/auto-discovery/cloud-aws/aws"
20-
"github.com/secureCodeBox/secureCodeBox/auto-discovery/cloud-aws/config"
21-
"github.com/secureCodeBox/secureCodeBox/auto-discovery/cloud-aws/kubernetes"
19+
"github.com/secureCodeBox/secureCodeBox/auto-discovery/cloud-aws/pkg/aws"
20+
"github.com/secureCodeBox/secureCodeBox/auto-discovery/cloud-aws/pkg/config"
21+
"github.com/secureCodeBox/secureCodeBox/auto-discovery/cloud-aws/pkg/kubernetes"
2222
configv1 "github.com/secureCodeBox/secureCodeBox/auto-discovery/kubernetes/api/v1"
2323
executionv1 "github.com/secureCodeBox/secureCodeBox/operator/apis/execution/v1"
2424
batchv1 "k8s.io/api/batch/v1"
@@ -62,7 +62,7 @@ var _ = BeforeSuite(func() {
6262

6363
By("bootstrapping test environment")
6464
testEnv = &envtest.Environment{
65-
CRDDirectoryPaths: []string{filepath.Join("..", "..", "operator", "config", "crd", "bases")},
65+
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "..", "operator", "config", "crd", "bases")},
6666
ErrorIfCRDPathMissing: true,
6767
}
6868

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313
"github.com/aws/aws-sdk-go/aws/session"
1414
"github.com/aws/aws-sdk-go/service/sqs"
1515
"github.com/go-logr/logr"
16-
"github.com/secureCodeBox/secureCodeBox/auto-discovery/cloud-aws/config"
17-
"github.com/secureCodeBox/secureCodeBox/auto-discovery/cloud-aws/kubernetes"
16+
"github.com/secureCodeBox/secureCodeBox/auto-discovery/cloud-aws/pkg/config"
17+
"github.com/secureCodeBox/secureCodeBox/auto-discovery/cloud-aws/pkg/kubernetes"
1818
)
1919

2020
type SQSAPI interface {

auto-discovery/cloud-aws/aws/ecs_events.go renamed to auto-discovery/cloud-aws/pkg/aws/ecs_events.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
awssdk "github.com/aws/aws-sdk-go/aws"
1111
"github.com/aws/aws-sdk-go/service/ecs"
1212
dockerparser "github.com/novln/docker-parser"
13-
"github.com/secureCodeBox/secureCodeBox/auto-discovery/cloud-aws/kubernetes"
13+
"github.com/secureCodeBox/secureCodeBox/auto-discovery/cloud-aws/pkg/kubernetes"
1414
)
1515

1616
type EcsTaskStateChange struct {

auto-discovery/cloud-aws/aws/events.go renamed to auto-discovery/cloud-aws/pkg/aws/events.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"encoding/json"
99
"errors"
1010

11-
"github.com/secureCodeBox/secureCodeBox/auto-discovery/cloud-aws/kubernetes"
11+
"github.com/secureCodeBox/secureCodeBox/auto-discovery/cloud-aws/pkg/kubernetes"
1212
)
1313

1414
type EventMessage struct {

auto-discovery/cloud-aws/aws/events_test.go renamed to auto-discovery/cloud-aws/pkg/aws/events_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
awssdk "github.com/aws/aws-sdk-go/aws"
1414
"github.com/aws/aws-sdk-go/service/ecs"
15-
"github.com/secureCodeBox/secureCodeBox/auto-discovery/cloud-aws/kubernetes"
15+
"github.com/secureCodeBox/secureCodeBox/auto-discovery/cloud-aws/pkg/kubernetes"
1616
)
1717

1818
var _ = Describe("AWS Events unit tests", func() {

0 commit comments

Comments
 (0)