gotool

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2022 License: MIT Imports: 15 Imported by: 0

README

go-tool#

Packet go-tool implements a way to use go more easily

Install

go get -u -v github.com/adimax2953/go-tool

Usage

Let's start with a trivial example:

package main

import (
	"github.com/adimax2953/go-tool"
	"fmt"
)

func main() {
    TgbotChatID := chatid
	TgbotToken :=  Telegram Bot Token 
	
	msg := fmt.Sprintf("\n事件:" + "山豬想睡覺了阿")
	gotool.SendToTG(TgbotChatID,TgbotToken,msg)
}

TODO

  1. Add TG Us test method.
  2. Improve or remove useless code.
  3. Check code formatting.

Documentation

Index

Constants

View Source
const (
	DateLayout     = "2006-01-02"
	TimeLayout     = "15:04:05"
	DateTimeLayout = "2006-01-02 15:04:05"
)

Variables

This section is empty.

Functions

func AbsInt32

func AbsInt32(n int32) int32

AbsInt32 -整數轉正

func BubbleSort

func BubbleSort(list []int32) []int32

氣泡排序Sli(小到大)

func DateFromNow

func DateFromNow() string

現在時間 格式為""2006-01-02""

func DateFromTimeStamp

func DateFromTimeStamp(timestamp int64) string

透過time.Now().Unix()出來的秒數轉為 "2006-01-02"

func FloatToStr

func FloatToStr(f float64) string

Float轉Str - 浮點數轉換成字符串

func Get

func Get(url string) (response string)

发送GET请求 url:请求地址 response:请求返回的内容

func GetStringEnd

func GetStringEnd(str string) string

GetStringEnd -取得字串最後一碼字

func Int32Sum

func Int32Sum(int32arr []int32) int32

int32 slice 加總

func Int32SumParallel

func Int32SumParallel(numbers []int32) int32

func Int32ToStr

func Int32ToStr(n int32) string

Int32轉str - 將整形轉換成字符串

func Int64ToStr

func Int64ToStr(n int64) string

Int64轉str - 將整形轉換成字符串

func IntArrEq

func IntArrEq(a, b []int) bool

IntArrEq - 兩個Int arr比較是否相等

func IntToStr

func IntToStr(n int) string

Int轉str - 將整形轉換成字符串

func Post

func Post(url string, data interface{}, contentType string) (content string)

发送POST请求 url:请求地址, data:POST请求提交的数据,contentType:请求体格式, 如:application/json content:请求放回的内容

func QuickSort

func QuickSort(list []int32, left int32, right int32)

func RanInt

func RanInt(num int) int

取亂數 1~num

func RemoveSliInt

func RemoveSliInt(slice []int32, elem int32) []int32

RemoveSliInt - 移除slice中的某個元素(int)

func RemoveSliStr

func RemoveSliStr(slice []string, elem string) []string

RemoveSliStr - 移除slice中的某個元素(str)

func Removeduplicate

func Removeduplicate(a interface{}) (ret []interface{})

func RemoveduplicateMap

func RemoveduplicateMap(DataArr []int32) []int32

去除重複資料 壓測效能優化

func RoundingFour

func RoundingFour(value float64) float64

RoundingFour - 四捨五入取小數四位

func RoundingSeven

func RoundingSeven(value float64) float64

RoundingSeven - 四捨五入取小數七位(後端統一)

func RoundingTwo

func RoundingTwo(value float64) float64

RoundingTwo - 四捨五入取小數兩位

func SearchSliFlt

func SearchSliFlt(slice []float64, elem float64) bool

SearchSliFlt - 檢查silce中有沒有此元素(float64)

func SearchSliInt

func SearchSliInt(slice []int, elem int) bool

SearchSliInt - 檢查silce中有沒有此元素(int)

func SearchSliInt32

func SearchSliInt32(slice []int32, elem int32) bool

SearchSliInt32 - 檢查silce中有沒有此元素(int32)

func SearchSliInt64

func SearchSliInt64(slice []int64, elem int64) bool

SearchSliInt64 - 檢查silce中有沒有此元素(int64)

func SearchSliStr

func SearchSliStr(slice []string, elem string) bool

SearchSliStr - 檢查silce中有沒有此元素(str)

func SendTextToTelegramChat

func SendTextToTelegramChat(chatId int, text string, Token string) (string, error)

SendTextToTelegramChat -發送訊息到TelegramChat

func SendToTG

func SendToTG(TgbotChatID int, TgbotToken, reson string)

func SliceMaxFloat64

func SliceMaxFloat64(l []float64) (max float64)

func SliceMinFloat64

func SliceMinFloat64(l []float64) (min float64)

func Str2Int

func Str2Int(str string) int

Str2Int - 字串轉Int

func Str2int32

func Str2int32(str string) (int32, error)

Str2int32 - 字串轉 Int32

func Str2int64

func Str2int64(str string) int64

Str2int64 - 字串轉Int64

func TimeFormatDate

func TimeFormatDate(timestamp int64) string
轉化成"2006-01-02 15:04:05"的時間模版

輸入為time.Now().Unix()

func TimeNowStr

func TimeNowStr() string

TimeNowStr 輸出格式為 2019/11/4 20:15:26

func TimestrToTimestamp

func TimestrToTimestamp(time_str string, flag int) int64

日期格式轉時間戳

Types

type Queue

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

func CreateQueue

func CreateQueue() *Queue

func (*Queue) Back

func (q *Queue) Back() interface{}

取得尾元素

func (*Queue) Begin

func (q *Queue) Begin() *QueueNode

取得首節點, 外部遍歷需要

func (*Queue) Clear

func (q *Queue) Clear()

func (*Queue) End

func (q *Queue) End() *QueueNode

取得尾節點, 外部遍歷需要

func (*Queue) Front

func (q *Queue) Front() interface{}

取得首元素

func (*Queue) Init

func (q *Queue) Init()

func (*Queue) PopFront

func (q *Queue) PopFront() interface{}

彈出首元素

func (*Queue) PushBack

func (q *Queue) PushBack(elem interface{})

func (*Queue) Range

func (q *Queue) Range(callback func(v interface{}) bool)

遍歷鍊錶

func (*Queue) Remove

func (q *Queue) Remove(ele interface{}) bool

傳入一個元素, 如果鍊錶中有, 即移除

func (*Queue) SetCapactiy

func (q *Queue) SetCapactiy(c uint32) uint32

一開始就要設置, 如果已經有了內容, 則只能設置為和當前容量一樣大小

func (*Queue) ShowSelf

func (q *Queue) ShowSelf()

func (*Queue) Size

func (q *Queue) Size() uint32

type QueueNode

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

先定義隊例節點

func (*QueueNode) Next

func (qn *QueueNode) Next() *QueueNode

func (*QueueNode) Value

func (qn *QueueNode) Value() interface{}

type Ticker

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

Ticker 定義一個Ticker,用於時間控制

type TickerManager

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

TickerManager 封裝一個tick的管理類,避免每次都要寫一大堆

func GetTickManager

func GetTickManager() *TickerManager

GetTickManager 得到tickmanage

func (*TickerManager) ClearTicker

func (tm *TickerManager) ClearTicker(id uint64)

ClearTicker 清除tick, 停止tick

func (*TickerManager) DelayExec

func (tm *TickerManager) DelayExec(callback func(), d time.Duration) uint64

DelayExec 延遲執行函數

func (*TickerManager) Init

func (tm *TickerManager) Init()

Init 初始化tickermanager, 就是設置起始id

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳