myfun

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2025 License: MIT Imports: 7 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

myfun

Some functions for go.

Install

go get github.com/gtlyy/myfun@v0.0.2

Licence

MIT License - see LICENSE for more details

Documentation

Overview

功能:实现一个广播器

功能:提供一些数据转化函数,以及一些常用函数。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArrayToString

func ArrayToString(a []string) string

字符串函数 =========================================== Start 将[]string{"aaa", "bbb", "ccc"} ---> "aaa,bbb,ccc"

func CountFloat

func CountFloat(f float64) int

计算小数点后有几位小数

func CountStrFloat

func CountStrFloat(sf string) int

计算小数点后有几位小数

func Float64ToInt

func Float64ToInt(f float64) int

float64 to int

func Float64ToInt64

func Float64ToInt64(f float64) int64

float64 to int64

func Float64ToString

func Float64ToString(arg float64, bit int) string

func IfError

func IfError(msg string, err error)

go 要写太多的错误检测函数了

func In

func In(target string, str_array []string) bool

查询字符串是否在数组中的函数

func Int64ToString

func Int64ToString(arg int64) string

func IntToString

func IntToString(arg int) string

数据转换 =========================================== Start

func JsonBytes2Struct

func JsonBytes2Struct(jsonBytes []byte, result interface{}) error

json byte array to struct

func JsonString2Struct

func JsonString2Struct(jsonString string, result interface{}) error

json string to struct

func ReadJSONFile

func ReadJSONFile(filePath string, data interface{}) error

ReadJSONFile 通用函数,用于读取 JSON 文件并解析数据到指定的结构体类型

func StringToFloat64

func StringToFloat64(arg string) float64

func StringToInt

func StringToInt(arg string) int

func StringToInt64

func StringToInt64(arg string) int64

func Struct2JsonString

func Struct2JsonString(structt interface{}) (jsonString string, err error)

struct to json string

func T3O

func T3O(condition bool, trueValue, falseValue interface{}) interface{}

实现三目运算:a == b ? c : d

func WriteJSONFile

func WriteJSONFile(filePath string, data interface{}) error

WriteJSONFile 通用函数,用于将指定的结构体数据写入到 JSON 文件中

Types

type Broadcaster

type Broadcaster struct {
	// contains filtered or unexported fields
}

广播器结构

func NewBroadcaster

func NewBroadcaster() *Broadcaster

func (*Broadcaster) Broadcast

func (b *Broadcaster) Broadcast(msg string)

向所有客户端广播消息

func (*Broadcaster) Close

func (b *Broadcaster) Close()

关闭所有客户端通道

func (*Broadcaster) Subscribe

func (b *Broadcaster) Subscribe() <-chan string

订阅新客户端

Jump to

Keyboard shortcuts

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