1
0
Fork 0

Adding upstream version 3.10.8.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-05-18 09:37:23 +02:00
parent 37e9b6d587
commit 03bfe4079e
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
356 changed files with 28857 additions and 0 deletions

36
id/id.go Normal file
View file

@ -0,0 +1,36 @@
// Copyright twenty-panda <twenty-panda@posteo.com>
// SPDX-License-Identifier: MIT
package id
import (
"fmt"
"code.forgejo.org/f3/gof3/v3/util"
)
type NodeID interface {
String() string
Int() int
Int64() int64
}
var NilID = NewNodeID("")
type nodeID string
func NewNodeID[T any](id T) NodeID {
return nodeID(fmt.Sprintf("%v", id))
}
func (o nodeID) String() string {
return string(o)
}
func (o nodeID) Int() int {
return int(o.Int64())
}
func (o nodeID) Int64() int64 {
return util.ParseInt(string(o))
}

21
id/id_test.go Normal file
View file

@ -0,0 +1,21 @@
// Copyright Earl Warren <contact@earl-warren.org>
// Copyright Loïc Dachary <loic@dachary.org>
// SPDX-License-Identifier: MIT
package id
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNodeID(t *testing.T) {
i := "1234"
id := NewNodeID(i)
assert.Equal(t, i, id.String())
v64 := int64(1234)
assert.Equal(t, v64, id.Int64())
v := int(1234)
assert.Equal(t, v, id.Int())
}