File: id.go

package info (click to toggle)
golang-code.forgejo-f3-gof3 3.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 1,952 kB
  • sloc: sh: 100; makefile: 65
file content (36 lines) | stat: -rw-r--r-- 524 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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))
}