generated from greenbone/go-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement create and list notification endpoints
- Loading branch information
Showing
18 changed files
with
738 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
with-expecter: true | ||
dir: "{{.InterfaceDir}}/mocks" | ||
outpkg: "mocks" | ||
mockname: "{{.InterfaceName}}" | ||
filename: "{{.InterfaceNameSnake}}.go" | ||
|
||
packages: | ||
github.com/greenbone/opensight-notification-service/pkg/port: | ||
interfaces: | ||
NotificationService: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
all: api-docs build test | ||
|
||
SWAG = github.com/swaggo/swag/cmd/[email protected] | ||
MOCKERY = github.com/vektra/mockery/[email protected] | ||
GOLANGCI-LINT = github.com/golangci/golangci-lint/cmd/golangci-lint@latest | ||
|
||
.PHONY: lint | ||
|
@@ -10,6 +11,11 @@ lint: | |
.PHONY: install-code-generation-tools | ||
install-code-generation-tools: | ||
go install $(SWAG) | ||
go install $(MOCKERY) | ||
|
||
.PHONY: generate-code | ||
generate-code: # create mocks | ||
go run $(MOCKERY) | ||
|
||
.PHONY: api-docs | ||
api-docs: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// SPDX-FileCopyrightText: 2024 Greenbone AG <https://greenbone.net> | ||
// | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
package helper | ||
|
||
func ToPtr[T any](val T) *T { | ||
return &val | ||
} | ||
|
||
// SafeDereference return the value ptr points to. If ptr is nil, it returns the default value if the type instead. | ||
func SafeDereference[T any](ptr *T) T { | ||
var zeroT T | ||
if ptr == nil { | ||
return zeroT | ||
} | ||
return *ptr | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// SPDX-FileCopyrightText: 2024 Greenbone AG <https://greenbone.net> | ||
// | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
package helper | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSafeDereference(t *testing.T) { | ||
type someStruct struct { | ||
foo, bar string | ||
} | ||
|
||
zeroValue := someStruct{} | ||
nonZeroValue := someStruct{foo: "aa", bar: "bb"} | ||
|
||
tests := []struct { | ||
name string | ||
input *someStruct | ||
want someStruct | ||
}{ | ||
{ | ||
name: "yields zero value with nil pointer", | ||
input: nil, | ||
want: zeroValue, | ||
}, | ||
{ | ||
name: "yields object pointed on for non-nil pointer", | ||
input: &nonZeroValue, | ||
want: nonZeroValue, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got := SafeDereference(tt.input) | ||
assert.Equal(t, tt.want, got) | ||
}) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.