toolbox

package module
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

README

file

LoadFile 加载ini,json,yaml文件

func LoadFile(config interface{}, file string, fileType int) (err error)


package main

import (
	"github.com/lailailee/toolbox/file"
)

type Config struct {
	Owner struct {
		Name         string `ini:"name"`
		Organization string `ini:"organization"`
	} `ini:"owner"`
	Database struct {
		Server   string `ini:"server"`
		Port     int    `ini:"port"`
		Type     string `ini:"type"`
		Username string `ini:"username"`
		Password string `ini:"password"`
	} `ini:"database"`
}

var config Config

file.LoadFile(&config, "config.ini", file.Ini)
file.LoadFile(&config, "config.json", file.Json)
file.LoadFile(&config, "config.yaml", file.Yaml)

Documentation

Index

Constants

View Source
const (
	LocalSubMsg = iota + 1
	LocalSysExit
	LocalRelayRsp
)

Variables

View Source
var Envirment = Darwin

Functions

func CheckFileIsExist

func CheckFileIsExist(filename string) bool

func CheckTcpPort added in v1.0.4

func CheckTcpPort(host string, port string) (e error)

CheckTcpPort 检查端口是否开放

func EncryptStringToMd5

func EncryptStringToMd5(str string) string

Md5 将字符串转为md5

func GenerateRandomNumber

func GenerateRandomNumber(start int, end int, count int) []int

GenerateRandomNumber 生成count个[start,end)结束的不重复的随机数

func InitEnvirment

func InitEnvirment(env Env)

InitEnvirment 初始化环境

func InitLogger added in v1.0.3

func InitLogger(lumberJackLogger LoggerConfig, debugLevel LoggerLevel) *zap.SugaredLogger

debugLevel : debug info error warn fatal InitLogger init logger

func IsDev

func IsDev() bool

IsDev 判断当前是否是开发环境 true 开发环境

func LoadFile

func LoadFile(config interface{}, file string, fileType FileType) (err error)

LoadFile 按类型读取文件

func ParseImageToBase64

func ParseImageToBase64(url string) (data string, e error)

ParseImageToBase64 是通过读取图片,并把图片转为base64格式,方便通过json传输

func ReadJsonFromFile

func ReadJsonFromFile(filename string, p interface{}) (err error)

func SaveBase64ToImage

func SaveBase64ToImage(picture string, finalPath string) (err error)

SaveBase64ToImage 将base64图片保存到指定路径

func SetJsonToFile

func SetJsonToFile(filename string, js string) (err error)

func ToByte added in v1.0.6

func ToByte(msg interface{}) []byte

Types

type Env

type Env string
const (
	Darwin  Env = "darwin"
	Linux   Env = "linux"
	Windows Env = "windows"
)

type FileType added in v1.0.2

type FileType int
const (
	Ini  FileType = 0
	Json FileType = 1
	Yaml FileType = 2
)

type LClient added in v1.0.5

type LClient struct {
	Client mqtt.Client
	Opts   *mqtt.ClientOptions

	LocalMsg   chan Message
	MqttConfig MqttConfig
	// contains filtered or unexported fields
}

LClient 的配置

func NewMqttClient added in v1.0.5

func NewMqttClient(cfg MqttConfig) *LClient

NewLocalClient create local client

func (*LClient) Connect added in v1.0.5

func (local *LClient) Connect()

Connect connect

func (*LClient) Publish added in v1.0.5

func (local *LClient) Publish(topic string, qos byte, retained bool, payload interface{}) error

func (*LClient) Run added in v1.0.5

func (local *LClient) Run()

Run

type LoggerConfig added in v1.0.3

type LoggerConfig lumberjack.Logger

type LoggerLevel added in v1.0.3

type LoggerLevel string
const (
	DebugLevel LoggerLevel = "debug"
	InfoLevel  LoggerLevel = "info"
	ErrorLevel LoggerLevel = "error"
	WarnLevel  LoggerLevel = "warn"
	FatalLevel LoggerLevel = "fatal"
)

type Message added in v1.0.5

type Message struct {
	Cmd      int
	Data     interface{}
	ModuleID int
}

type MqttConfig added in v1.0.5

type MqttConfig struct {
	Address     string
	UserName    string
	PassWord    string
	ClientID    string
	Logger      *zap.SugaredLogger
	Description string
	Subscribe   []string
	Handler     MqttHandler
}

type MqttHandler added in v1.0.5

type MqttHandler interface {
	ProcessPublish(msg mqtt.Message) (e error)
}

Jump to

Keyboard shortcuts

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