convert

package
v0.11.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2024 License: Apache-2.0 Imports: 16 Imported by: 3

Documentation

Overview

* @Author: kamalyes 501893067@qq.com * @Date: 2024-11-09 01:15:55 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2024-11-09 01:05:55 * @FilePath: \go-toolbox\pkg\convert\bytes.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.

* @Author: kamalyes 501893067@qq.com * @Date: 2024-11-09 01:00:55 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2024-11-09 01:00:55 * @FilePath: \go-toolbox\pkg\convert\ip.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.

* @Author: kamalyes 501893067@qq.com * @Date: 2024-08-03 21:32:26 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2024-11-13 09:06:59 * @FilePath: \go-toolbox\pkg\convert\must.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.

* @Author: kamalyes 501893067@qq.com * @Date: 2024-11-09 01:15:55 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2024-11-09 12:22:59 * @FilePath: \go-toolbox\pkg\convert\radix.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func B2S

func B2S(b []byte) string

B2S converts byte slice to string without a memory allocation. Slower: unsafe.String(unsafe.SliceData(b), len(b)) strings.Clone(): unsafe.String(&b[0], len(b))

func B64Decode

func B64Decode(s string) ([]byte, error)

B64Decode Base64 解码

func B64Encode

func B64Encode(data interface{}) (string, error)

B64Encode Base64 编码

func B64ToByte added in v0.11.5

func B64ToByte(imageBase64 string) ([]byte, error)

B64ToByte 将 Base64 字符串解码为字节切片 参数:imageBase64 - 要解码的 Base64 字符串 返回:解码后的字节切片和可能的错误

func B64UrlDecode

func B64UrlDecode(s string) ([]byte, error)

B64UrlDecode Base64 URL 安全解码

func B64UrlEncode

func B64UrlEncode(data interface{}) (string, error)

B64UrlEncode Base64 URL 安全编码

func ByteToBinStr

func ByteToBinStr(b byte) string

ByteToBinStr 将单个字节转换为二进制字符串

func BytesToBCC added in v0.11.5

func BytesToBCC(data []byte) byte

BytesBCC 计算字节数组的 BCC(块校验字符)

func BytesToBinStr

func BytesToBinStr(bs []byte) string

BytesToBinStr 将字节数组转换为二进制字符串

func BytesToBinStrWithSplit

func BytesToBinStrWithSplit(bs []byte, split string) string

BytesToBinStrWithSplit 将字节数组转换为二进制字符串,并添加分隔符

func BytesToHex

func BytesToHex(data []byte) string

BytesToHex 将字节数组转换为十六进制字符串

func DecToBin

func DecToBin(n uint64) string

DecToBin 将十进制数转换为二进制字符串,并补齐到8位。

func DecToHex

func DecToHex(n uint64) string

DecToHex 十进制转为十六进制字符串

func Float64ToInt added in v0.11.7

func Float64ToInt[T types.Numerical](value float64, mode RoundMode) (T, error)

Float64ToInt 将浮点数转换为整数类型,并进行取整

func HexToBCC added in v0.11.5

func HexToBCC(hexStr string) (string, error)

HexToBCC 计算十六进制字符串的 BCC

func HexToBin

func HexToBin(h string) (string, error)

HexToBin 将十六进制字符串转换为二进制字符串。 如果转换失败,则返回错误。

func HexToBytes

func HexToBytes(hexStr string) ([]byte, error)

HexToBytes 将十六进制字符串转换为字节数组。 如果十六进制字符串的长度为奇数或转换失败,则返回错误。

func HexToDec

func HexToDec(h string) (uint64, error)

HexToDec 将十六进制字符串转换为十进制数。 如果转换失败,则返回错误。

func IP2Long added in v0.11.5

func IP2Long(ip net.IP) (uint, error)

IP2Long 把net.IP转为数值

func Long2IP added in v0.11.5

func Long2IP(i uint) (net.IP, error)

Long2IP 把数值转为net.IP

func MustBool

func MustBool[T any](v T) bool

MustBool 强制转为 bool

func MustIntT added in v0.11.7

func MustIntT[T types.Numerical](value any, mode *RoundMode) (T, error)

MustIntT 将 any 转换为 T 类型

func MustJSON

func MustJSON(v interface{}) ([]byte, error)

MustJSON 转 json 返回 []byte

func MustJSONIndent

func MustJSONIndent(v interface{}) ([]byte, error)

MustJSONIndent 转 json 返回 []byte

func MustString

func MustString[T any](v T, timeLayout ...string) string

MustString 强制转为字符串

func NumberSliceToStringSlice added in v0.11.7

func NumberSliceToStringSlice[T types.Numerical](numbers []T) []string

NumberSliceToStringSlice Number切片转String

func ParseFloat added in v0.11.7

func ParseFloat[T types.Float](v string, value *T) error

ParseFloat 尝试将字符串解析为指定类型的浮点数

func S2B

func S2B(s string) []byte

S2B converts string to byte slice without a memory allocation. Ref: https://github.com/golang/go/issues/53003#issuecomment-1140276077

func SliceByteToString added in v0.11.5

func SliceByteToString(b []byte) string

SliceByteToString 将字节切片转换为字符串

func StringSliceToNumberSlice added in v0.11.7

func StringSliceToNumberSlice[T types.Numerical](strs []string, mode *RoundMode) ([]T, error)

StringSliceToNumberSlice 将字符串切片转换为数字切片

func StringToSliceByte added in v0.11.5

func StringToSliceByte(s string) []byte

StringToSliceByte 将字符串转换为字节切片

Types

type RoundMode added in v0.11.7

type RoundMode int

RoundMode 是一个枚举类型,用于指定取整的方式

const (
	RoundDown RoundMode = iota // 向下取整
	RoundUp                    // 向上取整
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL