diff options
Diffstat (limited to '')
-rw-r--r-- | forged/internal/common/misc/back.go (renamed from forged/internal/misc/back.go) | 0 | ||||
-rw-r--r-- | forged/internal/common/misc/iter.go (renamed from forged/internal/misc/iter.go) | 0 | ||||
-rw-r--r-- | forged/internal/common/misc/slices.go (renamed from forged/internal/misc/misc.go) | 1 | ||||
-rw-r--r-- | forged/internal/common/misc/trivial.go (renamed from forged/internal/misc/trivial.go) | 4 | ||||
-rw-r--r-- | forged/internal/common/misc/unsafe.go (renamed from forged/internal/misc/unsafe.go) | 4 | ||||
-rw-r--r-- | forged/internal/common/misc/url.go (renamed from forged/internal/misc/url.go) | 0 | ||||
-rw-r--r-- | forged/internal/misc/deploy.go | 22 | ||||
-rw-r--r-- | forged/internal/misc/panic.go | 19 |
8 files changed, 4 insertions, 46 deletions
diff --git a/forged/internal/misc/back.go b/forged/internal/common/misc/back.go index 5351359..5351359 100644 --- a/forged/internal/misc/back.go +++ b/forged/internal/common/misc/back.go diff --git a/forged/internal/misc/iter.go b/forged/internal/common/misc/iter.go index 61a96f4..61a96f4 100644 --- a/forged/internal/misc/iter.go +++ b/forged/internal/common/misc/iter.go diff --git a/forged/internal/misc/misc.go b/forged/internal/common/misc/slices.go index 398020a..3ad0211 100644 --- a/forged/internal/misc/misc.go +++ b/forged/internal/common/misc/slices.go @@ -1,7 +1,6 @@ // SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org> -// Package misc provides miscellaneous functions and other definitions. package misc import "strings" diff --git a/forged/internal/misc/trivial.go b/forged/internal/common/misc/trivial.go index e59c17e..83901e0 100644 --- a/forged/internal/misc/trivial.go +++ b/forged/internal/common/misc/trivial.go @@ -28,13 +28,13 @@ func QueryEscape(s string) string { } // Dereference dereferences a pointer. -func Dereference[T any](p *T) T { +func Dereference[T any](p *T) T { //nolint:ireturn return *p } // DereferenceOrZero dereferences a pointer. If the pointer is nil, the zero // value of its associated type is returned instead. -func DereferenceOrZero[T any](p *T) T { +func DereferenceOrZero[T any](p *T) T { //nolint:ireturn if p != nil { return *p } diff --git a/forged/internal/misc/unsafe.go b/forged/internal/common/misc/unsafe.go index 6c2192f..d827e7f 100644 --- a/forged/internal/misc/unsafe.go +++ b/forged/internal/common/misc/unsafe.go @@ -9,12 +9,12 @@ import "unsafe" // Memory is borrowed from the string. // The resulting byte slice must not be modified in any form. func StringToBytes(s string) (bytes []byte) { - return unsafe.Slice(unsafe.StringData(s), len(s)) + return unsafe.Slice(unsafe.StringData(s), len(s)) //#nosec G103 } // BytesToString converts a byte slice to a string without copying the bytes. // Memory is borrowed from the byte slice. // The source byte slice must not be modified. func BytesToString(b []byte) string { - return unsafe.String(unsafe.SliceData(b), len(b)) + return unsafe.String(unsafe.SliceData(b), len(b)) //#nosec G103 } diff --git a/forged/internal/misc/url.go b/forged/internal/common/misc/url.go index 346ff76..346ff76 100644 --- a/forged/internal/misc/url.go +++ b/forged/internal/common/misc/url.go diff --git a/forged/internal/misc/deploy.go b/forged/internal/misc/deploy.go deleted file mode 100644 index 3ee5f92..0000000 --- a/forged/internal/misc/deploy.go +++ /dev/null @@ -1,22 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only -// SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org> - -package misc - -import ( - "io" - "io/fs" - "os" -) - -// DeployBinary copies the contents of a binary file to the target destination path. -// The destination file is created with executable permissions. -func DeployBinary(src fs.File, dst string) (err error) { - var dstFile *os.File - if dstFile, err = os.OpenFile(dst, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o755); err != nil { - return err - } - defer dstFile.Close() - _, err = io.Copy(dstFile, src) - return err -} diff --git a/forged/internal/misc/panic.go b/forged/internal/misc/panic.go deleted file mode 100644 index 34c49c5..0000000 --- a/forged/internal/misc/panic.go +++ /dev/null @@ -1,19 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only -// SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org> - -package misc - -// FirstOrPanic returns the value or panics if the error is non-nil. -func FirstOrPanic[T any](v T, err error) T { - if err != nil { - panic(err) - } - return v -} - -// NoneOrPanic panics if the provided error is non-nil. -func NoneOrPanic(err error) { - if err != nil { - panic(err) - } -} |