Adding upstream version 3.10.8.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
37e9b6d587
commit
03bfe4079e
356 changed files with 28857 additions and 0 deletions
36
id/id.go
Normal file
36
id/id.go
Normal 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
21
id/id_test.go
Normal 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())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue