Skip to content
Merged
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
36 changes: 36 additions & 0 deletions .github/workflows/build-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
name: build-and-test

"on":
push:
branches:
- main
pull_request:

jobs:
build-and-test:
name: build-and-test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19

- name: Build
run: go build -v ./...

- name: Test
run: go test -v ./...
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.19
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
26 changes: 26 additions & 0 deletions .github/workflows/generic-linters.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
name: generic-linters

"on":
push:
branches:
- main
pull_request:


jobs:
yamllint:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Run yaml Lint
uses: actionshub/yamllint@main

mdl:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Run Markdown Lint
uses: actionshub/markdownlint@main
51 changes: 51 additions & 0 deletions .github/workflows/sec-code-scanning.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
name: "Code Scanning - Action"

"on":
push:
branches:
- main
pull_request:
# The branches below must be a subset of the branches above
branches:
- main
schedule:
- cron: '0 17 * * 5'

jobs:
codeQL:
# CodeQL runs on ubuntu-latest, windows-latest, and macos-latest
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
# Must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head of the pull request.
# Only include this option if you are running this workflow on pull requests.
fetch-depth: 2

# If this run was triggered by a pull request event then checkout
# the head of the pull request instead of the merge commit.
# Only include this step if you are running this workflow on pull requests.
- run: git checkout HEAD^2
if: ${{ github.event_name == 'pull_request' }}

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
# Override language selection by uncommenting this and choosing your languages
with:
languages: 'go'

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19

- name: Build
run: go build -v ./...

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
1 change: 1 addition & 0 deletions .mdlrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rules "~MD013"
13 changes: 13 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
extends: default
rules:
line-length:
max: 256
level: warning
document-start: disable
braces:
forbid: false
min-spaces-inside: 0
max-spaces-inside: 1
min-spaces-inside-empty: -1
max-spaces-inside-empty: -1
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# pointerhelpers
# pointer helpers

Go repo to hold all the helpers for pointers to save rewriting the same code every time

31 changes: 31 additions & 0 deletions int64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package pointerhelpers

// Int64Helper contains all Int64 related
// pointer helpers
type Int64Helper struct {
}

// Int64 returns a pointer to the int64 value passed in.
func Int64(v int64) *int64 {
return &v
}

// Int64 returns a pointer to the int64 value passed in.
func (i *Int64Helper) Int64(v int64) *int64 {
return Int64(v)
}

// Int64Value returns the value of the int64 pointer passed in or
// 0 if the pointer is nil.
func Int64Value(v *int64) int64 {
if v != nil {
return *v
}
return 0
}

// Int64Value returns the value of the int64 pointer passed in or
// 0 if the pointer is nil.
func (i *Int64Helper) Int64Value(v *int64) int64 {
return Int64Value(v)
}
28 changes: 28 additions & 0 deletions int64_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package pointerhelpers

import (
"github.com/stretchr/testify/assert"
"testing"
)

func TestInt(t *testing.T) {
h := StringHelper{}
want := "foo"
got := h.String(want)
assert.EqualValues(t, want, *got)
}

func TestStringValue(t *testing.T) {
t.Run("when nil returns empty string", func(t *testing.T) {
h := StringHelper{}
want := ""
got := h.StringValue(nil)
assert.Equal(t, want, got)
})
t.Run("when set returns the given string", func(t *testing.T) {
h := StringHelper{}
want := "foobar"
got := h.StringValue(String(want))
assert.Equal(t, want, got)
})
}
31 changes: 14 additions & 17 deletions string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,23 @@ import (
"testing"
)

// testify

func TestString(t *testing.T) {
h := StringHelper{}
want := "foo"
got := h.String(want)
func TestInt64(t *testing.T) {
h := Int64Helper{}
want := int64(42)
got := h.Int64(want)
assert.EqualValues(t, want, *got)
}

func TestStringValue(t *testing.T) {
t.Run("when nil returns empty string", func(t *testing.T) {
h := StringHelper{}
want := ""
got := h.StringValue(nil)
assert.Equal(t, want, got)
func TestInt64Value(t *testing.T) {
t.Run("when nil returns 0", func(t *testing.T) {
h := Int64Helper{}
got := h.Int64Value(nil)
assert.Equal(t, int64(0), got)
})
t.Run("when set returns the given string", func(t *testing.T) {
h := StringHelper{}
want := "foobar"
got := h.StringValue(String(want))
assert.Equal(t, want, got)
t.Run("when set returns the given int64", func(t *testing.T) {
h := Int64Helper{}
want := h.Int64(int64(42))
got := h.Int64Value(want)
assert.Equal(t, *want, got)
})
}
1 change: 1 addition & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ package pointerhelpers
// in this module to enable easier composition outside of this package
type PointerHelper struct {
StringHelper
Int64Helper
}