_function

package
v0.0.0-...-fc15aa7 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2025 License: GPL-3.0 Imports: 59 Imported by: 0

Documentation

Index

Constants

View Source
const BrowserUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36"
View Source
const ClientUserAgent = "tieba/" + ClientVersion
View Source
const ClientVersion = "12.58.1.0"
View Source
const ClientWidgetUserAgent = "TiebaWidgets/" + ClientVersion + " CFNetwork/3826.500.131 Darwin/24.5.0"
View Source
const ResetPwdExpire = 60 * 5 // 5 mins
View Source
const ResetPwdMaxTimes = 5

Variables

View Source
var CACertPool *x509.CertPool
View Source
var CanEncryptUserOption = []string{"go_bark_key", "go_ntfy_topic", "go_pushdeer_key"}
View Source
var DefaultCient *http.Client
View Source
var EchoEmptyArray = make([]string, 0)
View Source
var EchoEmptyObject = make(map[string]struct{}, 0)
View Source
var EmptyHeaders = make(map[string]string)
View Source
var GormDB = new(GormDBPool)
View Source
var IgnoreProxy bool
View Source
var LocalTime, _ = time.LoadLocation("Asia/Shanghai")

Tieba works in GMT+8

View Source
var MessageTypeList = []string{"email", "ntfy", "bark", "pushdeer"}
View Source
var Now = time.Now().In(LocalTime)
View Source
var ReleaseFilesPath = "https://github.com/BANKA2017/tbsign_go/releases/download"
View Source
var SettingsFilter = SettingsKeys
View Source
var SettingsKeys = []string{"ann", "icp", "system_url", "stop_reg", "enable_reg", "yr_reg", "cktime", "sign_mode", "sign_hour", "cron_limit", "sign_sleep", "retry_max", "mail_name", "mail_yourname", "mail_host", "mail_port", "mail_secure", "mail_auth", "mail_smtpname", "mail_smtppw", "go_forum_sync_policy", "go_ntfy_addr", "go_bark_addr", "go_pushdeer_addr", "go_export_personal_data", "go_import_personal_data", "go_re_check_in_max_interval", "sign_multith", "go_daily_report_hour", "bduss_num"} // "system_name", "system_keywords", "system_description", "tb_max"
View Source
var SyncForumListSf singleflight.Group
View Source
var TBClient *http.Client

Functions

func AES256GCMDecrypt

func AES256GCMDecrypt[T string | []byte](ciphertext T, key []byte) ([]byte, error)

func AES256GCMEncrypt

func AES256GCMEncrypt[T string | []byte](plaintext T, key []byte) ([]byte, error)

GCM Encryption/Decryption

func AddSign

func AddSign(form map[string]string, client_type string)

func Addslashes

func Addslashes(str string) string

func ApiTemplate

func ApiTemplate[T any](code int, message string, data T, version string) _type.ApiTemplate[T]

func Base64URLDecode

func Base64URLDecode(originalBuffer string) ([]byte, error)

func Base64URLEncode

func Base64URLEncode(originalBuffer []byte) string

func BoolToTinyInt

func BoolToTinyInt(b bool) int

func ConnectToMySQL

func ConnectToMySQL(username string, password string, endpoint string, dbname string, tlsOption string, logLevel logger.LogLevel, servicePrefix string) (*gorm.DB, *gorm.DB, error)

func ConnectToPgSQL

func ConnectToPgSQL(username string, password string, endpoint string, dbname string, tlsOption string, logLevel logger.LogLevel, servicePrefix string) (*gorm.DB, *gorm.DB, error)

TODO tlsOption, dsn format?

func ConnectToSQLite

func ConnectToSQLite(path string, logLevel logger.LogLevel, servicePrefix string) (*gorm.DB, *gorm.DB, error)

func CreatePasswordHash

func CreatePasswordHash(password string) ([]byte, error)

func DeleteOption

func DeleteOption(keyName string, ext ...any) error

func DeleteUserOption

func DeleteUserOption(keyName string, uid string, ext ...any) error

func EchoNoContent

func EchoNoContent(c echo.Context) error

func EchoReject

func EchoReject(c echo.Context) error

func Fetch

func Fetch(_url string, _method string, _body []byte, _headers map[string]string, client *http.Client) ([]byte, error)

func GenHMAC256

func GenHMAC256(ciphertext, key []byte) []byte

func GetBaiduUserInfo

func GetBaiduUserInfo(cookie _type.TypeCookie) (*_type.BaiduUserInfoResponse, error)

func GetCookie

func GetCookie(pid int32, ext ...bool) _type.TypeCookie

ext [bduss_only, force_sync]

func GetFid

func GetFid(name string) int64

func GetForumList

func GetForumList(cookie _type.TypeCookie, uid string, page int64) (*_type.ForumListResponse[*_type.ForumList], error)

func GetForumList2

func GetForumList2(cookie _type.TypeCookie, page int64) (*_type.ForumGuideResponse, error)

func GetForumNameShare

func GetForumNameShare(name string) (*_type.ForumNameShareResponse, error)
func GetGravatarLink(email string) string

func GetLoginQRCode

func GetLoginQRCode() (*_type.LoginQRCode, error)

func GetLoginResponse

func GetLoginResponse(tmpBDUSS string) (*_type.LoginResponse, error)

func GetManagerInfo

func GetManagerInfo(fid uint64) (*tbpb.GetBawuInfoResIdl_DataRes, error)

func GetManagerStatus

func GetManagerStatus(portrait string, fid int64) (*_type.IsManagerPreCheckResponse, error)

func GetManagerTasks

func GetManagerTasks(cookie _type.TypeCookie, fid int64) (*_type.ManagerTasksResponse, error)

func GetOption

func GetOption(keyName string) string

func GetSemver

func GetSemver(cur, ver2 string) string

func GetTbs

func GetTbs(bduss string) (*_type.TbsResponse, error)

func GetUnicastResponse

func GetUnicastResponse(sign string) (*_type.WrapUnicastResponse, error)

func GetUserInfoByTiebaUID

func GetUserInfoByTiebaUID(tbuid string) (*tbpb.GetUserByTiebaUidResIdl_DataRes, error)

func GetUserInfoByUsernameOrPortrait

func GetUserInfoByUsernameOrPortrait(requestType string, value string) (*_type.TiebaPanelUserInfoResponse, error)

func GetUserOption

func GetUserOption(keyName string, uid string, ext ...any) string

ext: []any{[]byte}

encryptKey

func GetWebForumList

func GetWebForumList(cookie _type.TypeCookie, page int64) (*_type.WebForumListResponse, error)

func HtmlSpecialchars

func HtmlSpecialchars(html string) string

func InitClient

func InitClient(timeout time.Duration) *http.Client

func InitOptions

func InitOptions()

func IsBinaryType

func IsBinaryType() bool

func IsOfficialSupport

func IsOfficialSupport() bool

func JsonDecode

func JsonDecode[T any](jsonByte []byte, template *T) error

func JsonEncode

func JsonEncode[T any](data T) ([]byte, error)

func LocaleTimeDiff

func LocaleTimeDiff(hour int64) int64

for GMT+8

func Md5

func Md5(str string) string

func MultipartBodyBuilder

func MultipartBodyBuilder(_body map[string][]byte, files ...MultipartBodyBinaryFileType) ([]byte, string, error)

func PostCheckinClient

func PostCheckinClient(cookie _type.TypeCookie, kw string, fid int32) (*_type.ClientSignResponse, error)

func PostClientBatchCheckin

func PostClientBatchCheckin(cookie _type.TypeCookie, fid []string) (*_type.BatchCheckinActionResponse, error)

func PostClientBatchCheckinForumList

func PostClientBatchCheckinForumList(cookie _type.TypeCookie) (*_type.BatchCheckinForumListResponse, error)

func PostForumInfoWidget

func PostForumInfoWidget(cookie _type.TypeCookie, fid int32) (any, error)

func PostSync

func PostSync(cookie _type.TypeCookie) (any, error)

!!! Calling this api will change the IP location !!! / DO NOT ASK ME WHY THE RESPONSE IS `ANY`!!!

func RandomEmoji

func RandomEmoji() string

func RandomTokenBuilder

func RandomTokenBuilder(n int64) ([]byte, error)

func RemoveLeadingZeros

func RemoveLeadingZeros(data []byte) []byte

from chatgpt

func ScanTiebaByPid

func ScanTiebaByPid(pid int32)

func SendBark

func SendBark(_to, title, body string) error

func SendEmail

func SendEmail(_to, title, body string) error

TODO GPG?

func SendMessage

func SendMessage(_type string, uid int32, _subject, _body string) error

func SendNtfy

func SendNtfy(_to, title, body string) error

func SendPushdeer

func SendPushdeer(_to, title, body string) error

func SetOption

func SetOption[T ~string | ~bool | ~int](keyName string, value T, ext ...any) error

func SetUserOption

func SetUserOption[T ~string | ~bool | ~int](keyName string, value T, uid string, ext ...any) error

ext: []any{*gorm.DB, []byte}

dbHandle, encryptKey

func Sha1

func Sha1(str string) string

func Sha256

func Sha256(str []byte) string

func TBFetch

func TBFetch(_url string, _method string, _body []byte, _headers map[string]string) ([]byte, error)

func TinyIntToBool

func TinyIntToBool(t int) bool

func UpdateNow

func UpdateNow()

func Upgrade

func Upgrade(version string) error

version = "20240707.c7990c7.6a6db54"

func VariablePtrWrapper

func VariablePtrWrapper[T any](anyValue T) *T

func VariableWrapper

func VariableWrapper[T any](anyValue T) T

func VerifyEmail

func VerifyEmail(email string) bool

func VerifyPasswordHash

func VerifyPasswordHash(hashedPassword string, password string) error

func VerifyURL

func VerifyURL(_url string) bool

func When

func When[T any](c bool, d1, d2 T) T

Types

type BarkResponseStruct

type BarkResponseStruct struct {
	Code      int    `json:"code,omitempty"`
	Message   string `json:"message,omitempty"`
	Timestamp int64  `json:"timestamp,omitempty"`
}

type GithubReleasesListResponseItem

type GithubReleasesListResponseItem struct {
	HTMLURL         string `json:"html_url,omitempty"`
	ID              int    `json:"id,omitempty"`
	TagName         string `json:"tag_name,omitempty"`
	TargetCommitish string `json:"target_commitish,omitempty"`
	Name            string `json:"name,omitempty"`
	Draft           bool   `json:"draft,omitempty"`
	Prerelease      bool   `json:"prerelease,omitempty"`
	CreatedAt       string `json:"created_at,omitempty"`
	PublishedAt     string `json:"published_at,omitempty"`
	Assets          []struct {
		URL                string `json:"url,omitempty"`
		Name               string `json:"name,omitempty"`
		State              string `json:"state,omitempty"`
		Size               int    `json:"size,omitempty"`
		CreatedAt          string `json:"created_at,omitempty"`
		UpdatedAt          string `json:"updated_at,omitempty"`
		BrowserDownloadURL string `json:"browser_download_url,omitempty"`
	} `json:"assets,omitempty"`
	Body string `json:"body,omitempty"`
}

type GormDBPool

type GormDBPool struct {
	R *gorm.DB
	W *gorm.DB
}

type KV

type KV[K, T any] struct {
	KV sync.Map
}
var CookieList KV[int32, _type.TypeCookie] //= make(map[int32]_type.TypeCookie)
var FidList KV[string, int64] //= make(map[string]int64)
var Options KV[string, string] //  make(map[string]string)

func (*KV[K, T]) Delete

func (list *KV[K, T]) Delete(key K)

func (*KV[K, T]) DeleteAll

func (list *KV[K, T]) DeleteAll()

func (*KV[K, T]) Length

func (list *KV[K, T]) Length() int

func (*KV[K, T]) Load

func (list *KV[K, T]) Load(key K) (T, bool)

func (*KV[K, T]) LoadAndDelete

func (list *KV[K, T]) LoadAndDelete(key K) (T, bool)

func (*KV[K, T]) Range

func (list *KV[K, T]) Range(f func(key K, value T) bool)

func (*KV[K, T]) RemoveExpired

func (list *KV[K, T]) RemoveExpired()

func (*KV[K, T]) Store

func (list *KV[K, T]) Store(key K, value T, ttlSeconds int64)

func (*KV[K, T]) TTL

func (list *KV[K, T]) TTL(key K) (int, bool)

Unix timestamp

type KVStruct

type KVStruct[T any] struct {
	Value    T     `json:"value"`
	ExpireAt int64 `json:"expire_at"`
}

type MultipartBodyBinaryFileType

type MultipartBodyBinaryFileType struct {
	Fieldname string
	Filename  string
	Binary    []byte
}

type NtfyResponseStruct

type NtfyResponseStruct struct {
	ID      string `json:"id,omitempty"`
	Time    int64  `json:"time,omitempty"`
	Expires int64  `json:"expires,omitempty"`
	Event   string `json:"event,omitempty"`
	Topic   string `json:"topic,omitempty"`
	Message string `json:"message,omitempty"`
}

type PushMessageTemplateStruct

type PushMessageTemplateStruct struct {
	Title string
	Body  string
}

func PushMessageTemplateResetPassword

func PushMessageTemplateResetPassword(verifyMessage, code string) PushMessageTemplateStruct

func PushMessageTestTemplate

func PushMessageTestTemplate() PushMessageTemplateStruct

type PushdeerResponseStruct

type PushdeerResponseStruct struct {
	Code  int    `json:"code,omitempty"`
	Error string `json:"error,omitempty"`
}

type StaticFSWrapper

type StaticFSWrapper struct {
	http.FileSystem
	FixedModTime time.Time
}

https://github.com/golang/go/issues/44854

func (*StaticFSWrapper) Open

func (f *StaticFSWrapper) Open(name string) (http.File, error)

type StaticFileInfoWrapper

type StaticFileInfoWrapper struct {
	os.FileInfo
	// contains filtered or unexported fields
}

func (*StaticFileInfoWrapper) ModTime

func (f *StaticFileInfoWrapper) ModTime() time.Time

type StaticFileWrapper

type StaticFileWrapper struct {
	http.File
	// contains filtered or unexported fields
}

func (*StaticFileWrapper) Stat

func (f *StaticFileWrapper) Stat() (os.FileInfo, error)

type VerifyCodeListType

type VerifyCodeListType struct {
	List KV[string, *VerifyCodeStruct]
}
var VerifyCodeList VerifyCodeListType //= make(map[int32]*ResetPwdStruct)

func (*VerifyCodeListType) DeleteCode

func (list *VerifyCodeListType) DeleteCode(_type string, uid int32)

func (*VerifyCodeListType) LoadCode

func (list *VerifyCodeListType) LoadCode(_type string, uid int32) (*VerifyCodeStruct, bool)

func (*VerifyCodeListType) StoreCode

func (list *VerifyCodeListType) StoreCode(_type string, uid int32, data *VerifyCodeStruct)

type VerifyCodeStruct

type VerifyCodeStruct struct {
	VerifyCode string `json:"verify_code"`
	Value      string `json:"value"`
	ResetTime  int64  `json:"time"`
	TryTime    int64  `json:"try_time"`
	Type       string `json:"type"`
	Expire     int64  `json:"expire"`
}

Jump to

Keyboard shortcuts

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