convert

package
v0.11.4 Latest Latest
Warning

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

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

Documentation

Overview

* @Author: kamalyes 501893067@qq.com * @Date: 2024-08-03 21:32:26 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2024-11-03 13:57:05 * @FilePath: \go-toolbox\pkg\convert\convert.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(b []byte) string

B64Encode Base64 编码

func B64UrlDecode

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

B64UrlDecode Base64 URL 安全解码

func B64UrlEncode

func B64UrlEncode(b []byte) string

B64UrlEncode Base64 URL 安全编码

func Base64ToByte

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

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

func ByteToBinStr

func ByteToBinStr(b byte) string

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

func BytesBCC

func BytesBCC(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 ConvertToInt

func ConvertToInt(v interface{}) (int, error)

ConvertToInt 将其他类型转换为 int

func DecToBin

func DecToBin(n uint64) string

DecToBin 十进制转为二进制字符串,补齐到8位

func DecToHex

func DecToHex(n uint64) string

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

func HexBCC

func HexBCC(hexStr string) (string, error)

HexBCC 计算十六进制字符串的 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 MustBool

func MustBool(v interface{}) bool

MustBool 强制转为 bool

func MustInt

func MustInt(v interface{}) (int, error)

MustInt 强制转换为整数 (int)

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(v interface{}, timeLayout ...string) string

MustString 强制转为字符串

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

Types

This section is empty.

Jump to

Keyboard shortcuts

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