Replace all interface{} to any
This commit is contained in:
@ -246,7 +246,7 @@ func (m Message) ClearString() string {
|
|||||||
|
|
||||||
// handle translate
|
// handle translate
|
||||||
if m.Translate != "" {
|
if m.Translate != "" {
|
||||||
args := make([]interface{}, len(m.With))
|
args := make([]any, len(m.With))
|
||||||
for i, v := range m.With {
|
for i, v := range m.With {
|
||||||
args[i] = v.ClearString()
|
args[i] = v.ClearString()
|
||||||
}
|
}
|
||||||
@ -291,7 +291,7 @@ func (m Message) String() string {
|
|||||||
|
|
||||||
// handle translate
|
// handle translate
|
||||||
if m.Translate != "" {
|
if m.Translate != "" {
|
||||||
args := make([]interface{}, len(m.With))
|
args := make([]any, len(m.With))
|
||||||
for i, v := range m.With {
|
for i, v := range m.With {
|
||||||
args[i] = v
|
args[i] = v
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
|
|
||||||
// Unmarshal decode binary NBT data and fill into v
|
// Unmarshal decode binary NBT data and fill into v
|
||||||
// This is a shortcut to `NewDecoder(bytes.NewReader(data)).Decode(v)`.
|
// This is a shortcut to `NewDecoder(bytes.NewReader(data)).Decode(v)`.
|
||||||
func Unmarshal(data []byte, v interface{}) error {
|
func Unmarshal(data []byte, v any) error {
|
||||||
_, err := NewDecoder(bytes.NewReader(data)).Decode(v)
|
_, err := NewDecoder(bytes.NewReader(data)).Decode(v)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -28,7 +28,7 @@ func Unmarshal(data []byte, v interface{}) error {
|
|||||||
//
|
//
|
||||||
// This method also return tag name of the root tag.
|
// This method also return tag name of the root tag.
|
||||||
// In real world, it is often empty, but the API should allow you to get it when ever you want.
|
// In real world, it is often empty, but the API should allow you to get it when ever you want.
|
||||||
func (d *Decoder) Decode(v interface{}) (string, error) {
|
func (d *Decoder) Decode(v any) (string, error) {
|
||||||
val := reflect.ValueOf(v)
|
val := reflect.ValueOf(v)
|
||||||
if val.Kind() != reflect.Ptr {
|
if val.Kind() != reflect.Ptr {
|
||||||
return "", errors.New("nbt: non-pointer passed to Decode")
|
return "", errors.New("nbt: non-pointer passed to Decode")
|
||||||
@ -329,7 +329,7 @@ func (d *Decoder) unmarshal(val reflect.Value, tagType byte) error {
|
|||||||
default:
|
default:
|
||||||
return errors.New("cannot parse TagList as " + vk.String())
|
return errors.New("cannot parse TagList as " + vk.String())
|
||||||
case reflect.Interface:
|
case reflect.Interface:
|
||||||
buf = reflect.ValueOf(make([]interface{}, listLen))
|
buf = reflect.ValueOf(make([]any, listLen))
|
||||||
case reflect.Slice:
|
case reflect.Slice:
|
||||||
buf = reflect.MakeSlice(val.Type(), int(listLen), int(listLen))
|
buf = reflect.MakeSlice(val.Type(), int(listLen), int(listLen))
|
||||||
case reflect.Array:
|
case reflect.Array:
|
||||||
@ -398,7 +398,7 @@ func (d *Decoder) unmarshal(val reflect.Value, tagType byte) error {
|
|||||||
val.SetMapIndex(reflect.ValueOf(tn), v.Elem())
|
val.SetMapIndex(reflect.ValueOf(tn), v.Elem())
|
||||||
}
|
}
|
||||||
case reflect.Interface:
|
case reflect.Interface:
|
||||||
buf := make(map[string]interface{})
|
buf := make(map[string]any)
|
||||||
for {
|
for {
|
||||||
tt, tn, err := d.readTag()
|
tt, tn, err := d.readTag()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -407,7 +407,7 @@ func (d *Decoder) unmarshal(val reflect.Value, tagType byte) error {
|
|||||||
if tt == TagEnd {
|
if tt == TagEnd {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
var value interface{}
|
var value any
|
||||||
if err = d.unmarshal(reflect.ValueOf(&value).Elem(), tt); err != nil {
|
if err = d.unmarshal(reflect.ValueOf(&value).Elem(), tt); err != nil {
|
||||||
return fmt.Errorf("fail to decode tag %q: %w", tn, err)
|
return fmt.Errorf("fail to decode tag %q: %w", tn, err)
|
||||||
}
|
}
|
||||||
@ -467,7 +467,7 @@ func indirect(v reflect.Value, decodingNull bool) (Unmarshaler, encoding.TextUnm
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Prevent infinite loop if v is an interface pointing to its own address:
|
// Prevent infinite loop if v is an interface pointing to its own address:
|
||||||
// var v interface{}
|
// var v any
|
||||||
// v = &v
|
// v = &v
|
||||||
if v.Elem().Kind() == reflect.Interface && v.Elem().Elem() == v {
|
if v.Elem().Kind() == reflect.Interface && v.Elem().Elem() == v {
|
||||||
v = v.Elem()
|
v = v.Elem()
|
||||||
|
@ -27,8 +27,8 @@ func TestUnmarshal_string(t *testing.T) {
|
|||||||
t.Errorf("Unmarshal NBT fail: get %q, want %q", Name, "Bananrama")
|
t.Errorf("Unmarshal NBT fail: get %q, want %q", Name, "Bananrama")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unmarshal to interface{}
|
// Unmarshal to any
|
||||||
var infName interface{}
|
var infName any
|
||||||
if err := Unmarshal(data, &infName); err != nil {
|
if err := Unmarshal(data, &infName); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -210,7 +210,7 @@ func TestDecoder_Decode_bigTest(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var inf interface{}
|
var inf any
|
||||||
r, err = gzip.NewReader(bytes.NewReader(bigTestData[:]))
|
r, err = gzip.NewReader(bytes.NewReader(bigTestData[:]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -313,7 +313,7 @@ func TestDecoder_Decode_LongArray(t *testing.T) {
|
|||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
value []int64
|
value []int64
|
||||||
infValue interface{}
|
infValue any
|
||||||
want = []int64{1, 2, 3}
|
want = []int64{1, 2, 3}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -342,7 +342,7 @@ func TestDecoder_Decode_ByteArray(t *testing.T) {
|
|||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
value []byte
|
value []byte
|
||||||
infValue interface{}
|
infValue any
|
||||||
want = []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}
|
want = []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -355,7 +355,7 @@ func TestDecoder_Decode_ByteArray(t *testing.T) {
|
|||||||
}
|
}
|
||||||
// t.Log(value)
|
// t.Log(value)
|
||||||
|
|
||||||
// Unmarshal to interface{}
|
// Unmarshal to any
|
||||||
if err := Unmarshal(data, &infValue); err != nil {
|
if err := Unmarshal(data, &infValue); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ import (
|
|||||||
// Marshal is the shortcut of NewEncoder().Encode() with empty tag name.
|
// Marshal is the shortcut of NewEncoder().Encode() with empty tag name.
|
||||||
// Notices that repeatedly init buffers is low efficiency.
|
// Notices that repeatedly init buffers is low efficiency.
|
||||||
// Using Encoder and Reset the buffer in each time is recommended in that cases.
|
// Using Encoder and Reset the buffer in each time is recommended in that cases.
|
||||||
func Marshal(v interface{}) ([]byte, error) {
|
func Marshal(v any) ([]byte, error) {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
err := NewEncoder(&buf).Encode(v, "")
|
err := NewEncoder(&buf).Encode(v, "")
|
||||||
return buf.Bytes(), err
|
return buf.Bytes(), err
|
||||||
@ -39,7 +39,7 @@ func NewEncoder(w io.Writer) *Encoder {
|
|||||||
// expect `[]int8`, `[]int32`, `[]int64`, `[]uint8`, `[]uint32` and `[]uint64`,
|
// expect `[]int8`, `[]int32`, `[]int64`, `[]uint8`, `[]uint32` and `[]uint64`,
|
||||||
// which TagByteArray, TagIntArray and TagLongArray.
|
// which TagByteArray, TagIntArray and TagLongArray.
|
||||||
// To force encode them as TagList, add a struct field tag.
|
// To force encode them as TagList, add a struct field tag.
|
||||||
func (e *Encoder) Encode(v interface{}, tagName string) error {
|
func (e *Encoder) Encode(v any, tagName string) error {
|
||||||
t, val := getTagType(reflect.ValueOf(v))
|
t, val := getTagType(reflect.ValueOf(v))
|
||||||
return e.marshal(val, t, tagName)
|
return e.marshal(val, t, tagName)
|
||||||
}
|
}
|
||||||
@ -242,7 +242,7 @@ func getTagType(v reflect.Value) (byte, reflect.Value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Prevent infinite loop if v is an interface pointing to its own address:
|
// Prevent infinite loop if v is an interface pointing to its own address:
|
||||||
// var v interface{}
|
// var v any
|
||||||
// v = &v
|
// v = &v
|
||||||
if v.Elem().Kind() == reflect.Interface && v.Elem().Elem() == v {
|
if v.Elem().Kind() == reflect.Interface && v.Elem().Elem() == v {
|
||||||
v = v.Elem()
|
v = v.Elem()
|
||||||
|
@ -112,12 +112,12 @@ func TestEncoder_Encode_interfaceArray(t *testing.T) {
|
|||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
args []interface{}
|
args []any
|
||||||
want []byte
|
want []byte
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Two element interface array",
|
name: "Two element interface array",
|
||||||
args: []interface{}{Struct1{3}, Struct2{0.3}},
|
args: []any{Struct1{3}, Struct2{0.3}},
|
||||||
want: []byte{
|
want: []byte{
|
||||||
TagList, 0x00, 0x00 /*no name*/, TagCompound, 0, 0, 0, 2,
|
TagList, 0x00, 0x00 /*no name*/, TagCompound, 0, 0, 0, 2,
|
||||||
// 1st element
|
// 1st element
|
||||||
@ -136,7 +136,7 @@ func TestEncoder_Encode_interfaceArray(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
} else if !bytes.Equal(data, tt.want) {
|
} else if !bytes.Equal(data, tt.want) {
|
||||||
t.Errorf("Marshal([]interface{}) got = % 02x, want % 02x", data, tt.want)
|
t.Errorf("Marshal([]any) got = % 02x, want % 02x", data, tt.want)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -242,7 +242,7 @@ func TestEncoder_Encode_map(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestEncoder_Encode_interface(t *testing.T) {
|
func TestEncoder_Encode_interface(t *testing.T) {
|
||||||
data := map[string]interface{}{
|
data := map[string]any{
|
||||||
"Key": int32(12),
|
"Key": int32(12),
|
||||||
"Value": "Tnze",
|
"Value": "Tnze",
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ func (m RawMessage) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Unmarshal decode the data into v.
|
// Unmarshal decode the data into v.
|
||||||
func (m RawMessage) Unmarshal(v interface{}) error {
|
func (m RawMessage) Unmarshal(v any) error {
|
||||||
d := NewDecoder(bytes.NewReader(m.Data))
|
d := NewDecoder(bytes.NewReader(m.Data))
|
||||||
val := reflect.ValueOf(v)
|
val := reflect.ValueOf(v)
|
||||||
if val.Kind() != reflect.Ptr {
|
if val.Kind() != reflect.Ptr {
|
||||||
|
@ -38,7 +38,7 @@ func (p Packet) Scan(fields ...FieldDecoder) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var bufPool = sync.Pool{
|
var bufPool = sync.Pool{
|
||||||
New: func() interface{} {
|
New: func() any {
|
||||||
return new(bytes.Buffer)
|
return new(bytes.Buffer)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -146,10 +146,10 @@ func ExamplePacket_Scan_joinGame() {
|
|||||||
PreGamemode pk.Byte
|
PreGamemode pk.Byte
|
||||||
WorldNames = []pk.Identifier{} // This cannot replace with "var DimensionNames []pk.Identifier" because "nil" has no type information
|
WorldNames = []pk.Identifier{} // This cannot replace with "var DimensionNames []pk.Identifier" because "nil" has no type information
|
||||||
DimensionCodec struct {
|
DimensionCodec struct {
|
||||||
DimensionType interface{} `nbt:"minecraft:dimension_type"`
|
DimensionType any `nbt:"minecraft:dimension_type"`
|
||||||
WorldgenBiome interface{} `nbt:"minecraft:worldgen/biome"`
|
WorldgenBiome any `nbt:"minecraft:worldgen/biome"`
|
||||||
}
|
}
|
||||||
Dimension interface{}
|
Dimension any
|
||||||
WorldName pk.Identifier
|
WorldName pk.Identifier
|
||||||
HashedSeed pk.Long
|
HashedSeed pk.Long
|
||||||
MaxPlayers pk.VarInt
|
MaxPlayers pk.VarInt
|
||||||
@ -181,7 +181,7 @@ func ExampleMarshal_setSlot() {
|
|||||||
Present bool
|
Present bool
|
||||||
ItemID int
|
ItemID int
|
||||||
ItemCount byte
|
ItemCount byte
|
||||||
NBT interface{}
|
NBT any
|
||||||
}{
|
}{
|
||||||
{WindowID: 0, Slot: 5, Present: false},
|
{WindowID: 0, Slot: 5, Present: false},
|
||||||
{WindowID: 0, Slot: 5, Present: true, ItemID: 0x01, ItemCount: 1, NBT: pk.Byte(0)},
|
{WindowID: 0, Slot: 5, Present: true, ItemID: 0x01, ItemCount: 1, NBT: pk.Byte(0)},
|
||||||
|
@ -467,7 +467,7 @@ func (d *Double) ReadFrom(r io.Reader) (n int64, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NBT encode a value as Named Binary Tag
|
// NBT encode a value as Named Binary Tag
|
||||||
func NBT(v interface{}, optionalTagName ...string) Field {
|
func NBT(v any, optionalTagName ...string) Field {
|
||||||
if len(optionalTagName) > 0 {
|
if len(optionalTagName) > 0 {
|
||||||
return nbtField{V: v, FieldName: optionalTagName[0]}
|
return nbtField{V: v, FieldName: optionalTagName[0]}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ var (
|
|||||||
//
|
//
|
||||||
// Note that Ary DO read or write the Len. You aren't need to do so by your self.
|
// Note that Ary DO read or write the Len. You aren't need to do so by your self.
|
||||||
type Ary[LEN VarInt | VarLong | Byte | UnsignedByte | Short | UnsignedShort | Int | Long] struct {
|
type Ary[LEN VarInt | VarLong | Byte | UnsignedByte | Short | UnsignedShort | Int | Long] struct {
|
||||||
Ary interface{} // Slice or Pointer of Slice of FieldEncoder, FieldDecoder or both (Field)
|
Ary any // Slice or Pointer of Slice of FieldEncoder, FieldDecoder or both (Field)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a Ary[LEN]) WriteTo(w io.Writer) (n int64, err error) {
|
func (a Ary[LEN]) WriteTo(w io.Writer) (n int64, err error) {
|
||||||
|
@ -90,7 +90,7 @@ func (r *RCONConn) ReadPacket() (RequestID, Type int32, Payload string, err erro
|
|||||||
func (r *RCONConn) WritePacket(RequestID, Type int32, Payload string) error {
|
func (r *RCONConn) WritePacket(RequestID, Type int32, Payload string) error {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
|
|
||||||
for _, v := range []interface{}{
|
for _, v := range []any{
|
||||||
int32(4 + 4 + len(Payload) + 2), // Length
|
int32(4 + 4 + len(Payload) + 2), // Length
|
||||||
RequestID, // Request ID
|
RequestID, // Request ID
|
||||||
Type, // Type
|
Type, // Type
|
||||||
|
@ -52,7 +52,7 @@ func New(version, user, astk, uuid string) *Realms {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Realms) get(endpoint string, resp interface{}) error {
|
func (r *Realms) get(endpoint string, resp any) error {
|
||||||
rawResp, err := r.c.Get(Domain + endpoint)
|
rawResp, err := r.c.Get(Domain + endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -67,7 +67,7 @@ func (r *Realms) get(endpoint string, resp interface{}) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Realms) post(endpoint string, payload, resp interface{}) error {
|
func (r *Realms) post(endpoint string, payload, resp any) error {
|
||||||
data, err := json.Marshal(payload)
|
data, err := json.Marshal(payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -23,7 +23,7 @@ type Server struct {
|
|||||||
MiniGameID *int
|
MiniGameID *int
|
||||||
MinigameImage *string
|
MinigameImage *string
|
||||||
ActiveSlot int
|
ActiveSlot int
|
||||||
// Slots interface{}
|
// Slots any
|
||||||
Member bool
|
Member bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,8 +38,8 @@ type WorldGenSettings struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type DimensionGenerator struct {
|
type DimensionGenerator struct {
|
||||||
Type string `nbt:"type"`
|
Type string `nbt:"type"`
|
||||||
Generator map[string]interface{} `nbt:"generator"`
|
Generator map[string]any `nbt:"generator"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -47,7 +47,7 @@ var (
|
|||||||
DefaultDimensionsGenerators = map[string]DimensionGenerator{
|
DefaultDimensionsGenerators = map[string]DimensionGenerator{
|
||||||
"minecraft:overworld": {
|
"minecraft:overworld": {
|
||||||
Type: "minecraft:overworld",
|
Type: "minecraft:overworld",
|
||||||
Generator: map[string]interface{}{
|
Generator: map[string]any{
|
||||||
"type": "minecraft:noise",
|
"type": "minecraft:noise",
|
||||||
"settings": "minecraft:overworld",
|
"settings": "minecraft:overworld",
|
||||||
"biome_source": map[string]string{
|
"biome_source": map[string]string{
|
||||||
@ -58,7 +58,7 @@ var (
|
|||||||
},
|
},
|
||||||
"minecraft:the_end": {
|
"minecraft:the_end": {
|
||||||
Type: "minecraft:the_end",
|
Type: "minecraft:the_end",
|
||||||
Generator: map[string]interface{}{
|
Generator: map[string]any{
|
||||||
"type": "minecraft:noise",
|
"type": "minecraft:noise",
|
||||||
"settings": "minecraft:end",
|
"settings": "minecraft:end",
|
||||||
"biome_source": map[string]string{
|
"biome_source": map[string]string{
|
||||||
@ -68,7 +68,7 @@ var (
|
|||||||
},
|
},
|
||||||
"minecraft:the_nether": {
|
"minecraft:the_nether": {
|
||||||
Type: "minecraft:the_nether",
|
Type: "minecraft:the_nether",
|
||||||
Generator: map[string]interface{}{
|
Generator: map[string]any{
|
||||||
"type": "minecraft:noise",
|
"type": "minecraft:noise",
|
||||||
"settings": "minecraft:nether",
|
"settings": "minecraft:nether",
|
||||||
"biome_source": map[string]string{
|
"biome_source": map[string]string{
|
||||||
|
@ -46,7 +46,7 @@ type LevelData struct {
|
|||||||
LastPlayed int64
|
LastPlayed int64
|
||||||
LevelName string
|
LevelName string
|
||||||
MapFeatures bool
|
MapFeatures bool
|
||||||
Player map[string]interface{}
|
Player map[string]any
|
||||||
Raining bool `nbt:"raining"`
|
Raining bool `nbt:"raining"`
|
||||||
RainTime int32 `nbt:"rainTime"`
|
RainTime int32 `nbt:"rainTime"`
|
||||||
RandomSeed int64
|
RandomSeed int64
|
||||||
|
@ -72,8 +72,8 @@ type PlayerData struct {
|
|||||||
type Item struct {
|
type Item struct {
|
||||||
Count byte
|
Count byte
|
||||||
Slot byte
|
Slot byte
|
||||||
ID string `nbt:"id"`
|
ID string `nbt:"id"`
|
||||||
Tag map[string]interface{} `nbt:"tag"`
|
Tag map[string]any `nbt:"tag"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadPlayerData(r io.Reader) (data PlayerData, err error) {
|
func ReadPlayerData(r io.Reader) (data PlayerData, err error) {
|
||||||
|
@ -43,7 +43,7 @@ func TestReadRegion(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
var b interface{}
|
var b any
|
||||||
_, err = nbt.NewDecoder(r).Decode(&b)
|
_, err = nbt.NewDecoder(r).Decode(&b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
|
@ -54,7 +54,7 @@ func (g *Graph) Execute(ctx context.Context, cmd string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type ParsedData interface{}
|
type ParsedData any
|
||||||
|
|
||||||
type HandlerFunc func(ctx context.Context, args []ParsedData) error
|
type HandlerFunc func(ctx context.Context, args []ParsedData) error
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ func (t *Tree[I, B, V]) Insert(leaf B, value V) (n *Node[I, B, V]) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tree[I, B, V]) Delete(n *Node[I, B, V]) interface{} {
|
func (t *Tree[I, B, V]) Delete(n *Node[I, B, V]) any {
|
||||||
if n.parent == nil {
|
if n.parent == nil {
|
||||||
// n is the root
|
// n is the root
|
||||||
t.root = nil
|
t.root = nil
|
||||||
@ -204,11 +204,11 @@ type (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h searchHeap[I, V]) Len() int { return len(h) }
|
func (h searchHeap[I, V]) Len() int { return len(h) }
|
||||||
func (h searchHeap[I, V]) Less(i, j int) bool { return h[i].inheritedCost < h[j].inheritedCost }
|
func (h searchHeap[I, V]) Less(i, j int) bool { return h[i].inheritedCost < h[j].inheritedCost }
|
||||||
func (h searchHeap[I, V]) Swap(i, j int) { h[i], h[j] = h[j], h[i] }
|
func (h searchHeap[I, V]) Swap(i, j int) { h[i], h[j] = h[j], h[i] }
|
||||||
func (h *searchHeap[I, V]) Push(x interface{}) { *h = append(*h, x.(searchItem[I, V])) }
|
func (h *searchHeap[I, V]) Push(x any) { *h = append(*h, x.(searchItem[I, V])) }
|
||||||
func (h *searchHeap[I, V]) Pop() interface{} {
|
func (h *searchHeap[I, V]) Pop() any {
|
||||||
old := *h
|
old := *h
|
||||||
n := len(old)
|
n := len(old)
|
||||||
x := old[n-1]
|
x := old[n-1]
|
||||||
|
@ -54,7 +54,7 @@ func fetchKeyPair(accessToken string) (KeyPairResp, error) {
|
|||||||
return keyPairResp, err
|
return keyPairResp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func post(endpoint string, accessToken string, resp interface{}) error {
|
func post(endpoint string, accessToken string, resp any) error {
|
||||||
rowResp, err := rawPost(endpoint, accessToken)
|
rowResp, err := rawPost(endpoint, accessToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("request fail: %v", err)
|
return fmt.Errorf("request fail: %v", err)
|
||||||
|
@ -28,7 +28,7 @@ var AuthURL = "https://authserver.mojang.com"
|
|||||||
|
|
||||||
var client = http.DefaultClient
|
var client = http.DefaultClient
|
||||||
|
|
||||||
func post(endpoint string, payload interface{}, resp interface{}) error {
|
func post(endpoint string, payload any, resp any) error {
|
||||||
rowResp, err := rawPost(endpoint, payload)
|
rowResp, err := rawPost(endpoint, payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("request fail: %v", err)
|
return fmt.Errorf("request fail: %v", err)
|
||||||
@ -43,7 +43,7 @@ func post(endpoint string, payload interface{}, resp interface{}) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func rawPost(endpoint string, payload interface{}) (*http.Response, error) {
|
func rawPost(endpoint string, payload any) (*http.Response, error) {
|
||||||
data, err := json.Marshal(payload)
|
data, err := json.Marshal(payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("marshal payload fail: %v", err)
|
return nil, fmt.Errorf("marshal payload fail: %v", err)
|
||||||
|
Reference in New Issue
Block a user