xjutils

package module
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2021 License: Apache-2.0 Imports: 43 Imported by: 0

README

xjutil

介绍

xjutil,星杰工具包 1.

软件架构
  1. 本工具包采用go语言编写

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//Db      *xorm.Engine
	Gorm    *gorm.DB
	Redisdb *redis.Client
)
View Source
var (
	GitCommit = "7b32838"
	BuildTime = "2020-05-10 12:29"
	GoVersion = "1.14"
	Version   = "0.0.1"
)

set on build time

View Source
var Config *ini.File

Functions

func BeegoServeJSON

func BeegoServeJSON(ctx *context.Context, data interface{})

func BytesToInt64

func BytesToInt64(buf []byte) int64

func Camel2Case

func Camel2Case(name string) string

************************************** 其他方法 ************************************** 驼峰式写法转为下划线写法

func Capitalize

func Capitalize(str string) string

Capitalize 字符首字母大写

func Case2Camel

func Case2Camel(name string) string

下划线写法转为驼峰写法

func ContainsInt

func ContainsInt(list []int, item int) bool

func ContainsInt64

func ContainsInt64(list []int64, item int64) bool

func ContainsString

func ContainsString(list []string, item string) bool

func CopyStruct

func CopyStruct(src, dst interface{})

func Count

func Count(db *gorm.DB, sql string) (total int64)

func DeepFields

func DeepFields(ifaceType reflect.Type) []reflect.StructField

func EtcdGet

func EtcdGet(endpoints []string, key string) map[string]string

func EtcdPut

func EtcdPut(endpoints []string, key, value string) error

func Float64Round

func Float64Round(value float64, scale int) float64

func Float64ToInt

func Float64ToInt(val float64) int

func Float64ToInt64

func Float64ToInt64(val float64) int64

func GetBearerToken

func GetBearerToken(ctx *gin.Context) (string, error)

func GetChineseFirstLetter

func GetChineseFirstLetter(chinese string) string

获取中文字符串第一个首字母

func GormInit

func GormInit(datasource Datasource) *gorm.DB
func XormInit(Conf NacAppConfig) *xorm.Engine {
	dataSourceName := Conf.Datasource.Username + ":" + Conf.Datasource.Password + "@tcp(" + Conf.Datasource.Url + ":" + Conf.Datasource.Port + ")/" + Conf.Datasource.Database + "?charset=utf8&parseTime=True&loc=Asia%2fShanghai"
	Db, err := xorm.NewEngine(Conf.Datasource.Drivername, dataSourceName)
	if err = Db.Ping(); err != nil {
		fmt.Println("数据库连接失败")
		os.Exit(1)
	}
	Db.ShowSQL(true)
	return Db
}

func GormSqlServerInit

func GormSqlServerInit(Conf NacAppConfig) *gorm.DB

func Health

func Health(c *gin.Context)

func HttpGetStr

func HttpGetStr(url string) (string, error)

func HttpGetStrWithToken

func HttpGetStrWithToken(url, token string) string

func HttpGetStrWithTokenInner

func HttpGetStrWithTokenInner(url, token string) (string, error)

func HttpPostStrJson

func HttpPostStrJson(url, json string) (string, error)

func HttpPostStrWithToken

func HttpPostStrWithToken(url, token string) string

func HttpPostStrWithTokenJson

func HttpPostStrWithTokenJson(url, token, json string) (string, error)

func Init

func Init()

func Int64ArrayToInterfaceArray

func Int64ArrayToInterfaceArray(ints []int64) []interface{}

func Int64ArrayToString

func Int64ArrayToString(ints []int64) string

func Int64ToBytes

func Int64ToBytes(i int64) []byte

func IntArrayToString

func IntArrayToString(ints []int) string

func IntToFloat64

func IntToFloat64(val int) float64

func InterfaceArrayToInt64Array

func InterfaceArrayToInt64Array(src []interface{}) ([]int64, error)

func InterfaceToBool

func InterfaceToBool(val interface{}) bool

func InterfaceToFloat64

func InterfaceToFloat64(val interface{}) float64

func InterfaceToInt

func InterfaceToInt(val interface{}) int

func InterfaceToInt64

func InterfaceToInt64(val interface{}) int64

func InterfaceToString

func InterfaceToString(val interface{}) string

func JsonToIntArray

func JsonToIntArray(str string) ([]int, error)

func Lcfirst

func Lcfirst(str string) string

首字母小写

func Loadconf

func Loadconf()

func LogDebug

func LogDebug(str string)

func LogError

func LogError(str string)

func LogInfo

func LogInfo(str string)

func LogOutput

func LogOutput(str, prefix string, calldepin int)

func LogPrefix

func LogPrefix(str, prefix string)

func LogWarn

func LogWarn(str string)

func MapToEntityWithOutType

func MapToEntityWithOutType(src map[string]interface{}, dst interface{})

*

  • Map转实体类
  • @param map 需要初始化的数据,key字段必须与实体类的成员名字一样,否则赋值为空
  • @param entity 需要转化成的实体类
  • @return

func MapToEntityWithOutTypeDeep

func MapToEntityWithOutTypeDeep(src map[string]interface{}, dst interface{}) interface{}

//Map转实体类(包含子struct)

func Md5V

func Md5V(str string) string

func Md5V2

func Md5V2(str string) string

func Md5V3

func Md5V3(str string) string

func NacosGetService

func NacosGetService(appConfig AppConfig, serviceName string) (string, error)

func NacosRegisterService

func NacosRegisterService(appConfig AppConfig) (naming_client.INamingClient, error)

func NacosSelectInstances

func NacosSelectInstances(appConfig AppConfig, serviceName, prefix string) (string, error)

func PathVariableFloat32

func PathVariableFloat32(ctx *gin.Context, key string) (v float32)

func PathVariableFloat64

func PathVariableFloat64(ctx *gin.Context, key string) (v float64)

func PathVariableInt

func PathVariableInt(ctx *gin.Context, key string) (v int)

func PathVariableInt64

func PathVariableInt64(ctx *gin.Context, key string) (v int64)

func PathVariableString

func PathVariableString(ctx *gin.Context, key string) (v string)

func PrintVersion

func PrintVersion()

PrintVersion Print out version information

func QueryFloat64

func QueryFloat64(ctx *gin.Context, key string) (v float64)

func QueryInt

func QueryInt(ctx *gin.Context, key string) (v int)

func QueryInt64

func QueryInt64(ctx *gin.Context, key string) (v int64)

func QueryIntDefault

func QueryIntDefault(ctx *gin.Context, key string, d int) (v int)

func QueryMap

func QueryMap(ctx *gin.Context) (m map[string]interface{})

func RedisInit

func RedisInit(conf Redis) *redis.Client

func Refresh

func Refresh(c *gin.Context)

func Register

func Register()

func RequestBody

func RequestBody(ctx *gin.Context, dst interface{})

func RpcxCall

func RpcxCall(etcdAddr []string, servicePath, method string, args interface{}) (reply interface{}, err error)

func RpcxCallByte

func RpcxCallByte(etcdAddr []string, servicePath, method string, args interface{}) (reply []byte, err error)

func RpcxCallStr

func RpcxCallStr(etcdAddr []string, servicePath, method string, args interface{}) (reply string, err error)

func SelectOneHealthyInstance

func SelectOneHealthyInstance(client naming_client.INamingClient, IpAddr string, Port uint64, ServiceName string) (instance string, err error)

func SpecialChar

func SpecialChar(src string) string

func StrToUnix

func StrToUnix(timeStr, layout string) (int64, error)

时间转时间戳

func StringToInt64Array

func StringToInt64Array(s string) ([]int64, error)

func StringToIntArray

func StringToIntArray(s string) ([]int, error)

func StringToInterfaceArray

func StringToInterfaceArray(s string) ([]interface{}, error)

func StructCopy

func StructCopy(DstStructPtr interface{}, SrcStructPtr interface{})

func Ucfirst

func Ucfirst(str string) string

首字母大写

func UnixToStr

func UnixToStr(timeUnix int64, layout string) string

时间戳转时间

func Utf8ToGbk

func Utf8ToGbk(s []byte) ([]byte, error)

Utf8ToGbk

Types

type AppConfig

type AppConfig struct {
	App struct {
		Name    string
		Url     string
		Port    uint64
		Rpcport uint64
	}
	Register struct {
		Url         string
		Port        uint64
		Kind        string
		NamespaceId string
		Group       string
	}
	Config struct {
		Url         string
		Port        uint64
		Kind        string
		NamespaceId string
		Group       string
		DataId      string
		PubDataId   string
	}
	Gateway struct {
		Url  string
		Port uint64
	}
}

func GetAppConfig

func GetAppConfig(profile string) AppConfig

type Buffer

type Buffer struct {
	*bytes.Buffer
}

内嵌bytes.Buffer,支持连写

func NewBuffer

func NewBuffer() *Buffer

func (*Buffer) Append

func (b *Buffer) Append(i interface{}) *Buffer

type ClientDis

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

func NewClientDis

func NewClientDis(addr []string) (*ClientDis, error)

func (*ClientDis) DelServiceList

func (this *ClientDis) DelServiceList(key string)

func (*ClientDis) GetServerList

func (this *ClientDis) GetServerList() map[string][]*url.URL

func (*ClientDis) GetService

func (this *ClientDis) GetService(prefix string) ([]string, error)

func (*ClientDis) SerList2Array

func (this *ClientDis) SerList2Array() []string

func (*ClientDis) SetServiceList

func (this *ClientDis) SetServiceList(key, val string)

type Datasource

type Datasource struct {
	Drivername string
	Url        string
	Port       string
	Username   string
	Password   string
	Database   string
}

type EsDate

type EsDate time.Time

func (EsDate) MarshalJSON

func (t EsDate) MarshalJSON() ([]byte, error)

func (*EsDate) UnmarshalJSON

func (t *EsDate) UnmarshalJSON(data []byte) (err error)

type EsTime

type EsTime time.Time

func (EsTime) MarshalJSON

func (t EsTime) MarshalJSON() ([]byte, error)

func (*EsTime) UnmarshalJSON

func (t *EsTime) UnmarshalJSON(data []byte) (err error)

type Json

type Json string

func (Json) MarshalJSON

func (j Json) MarshalJSON() ([]byte, error)

func (*Json) UnmarshalJSON

func (j *Json) UnmarshalJSON(data []byte) (err error)

type JsonCamelCase

type JsonCamelCase struct {
	Value interface{}
}

************************************** 驼峰json **************************************

func (JsonCamelCase) MarshalJSON

func (c JsonCamelCase) MarshalJSON() ([]byte, error)

type JsonSnakeCase

type JsonSnakeCase struct {
	Value interface{}
}

************************************** 下划线json **************************************

func (JsonSnakeCase) MarshalJSON

func (c JsonSnakeCase) MarshalJSON() ([]byte, error)

type NacAppConfig

type NacAppConfig struct {
	Etcd struct {
		Url       []string
		LeaseTime int64
	}
	Datasource Datasource
	Redis      Redis
}

func GetNacAppConfig

func GetNacAppConfig(appConfig AppConfig, profile string) (string, string, NacAppConfig)

type Redis

type Redis struct {
	Addr     string
	Password string
	DB       int
}

type RegItem

type RegItem struct {
	Url        string
	Status     string
	Createtime time.Time
	Updatetime time.Time
}

type ServiceReg

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

创建租约注册服务

func NewServiceReg

func NewServiceReg(addr []string, timeNum int64) *ServiceReg

func (*ServiceReg) ListenLeaseRespChan

func (this *ServiceReg) ListenLeaseRespChan()

监听 续租情况

func (*ServiceReg) PutService

func (this *ServiceReg) PutService(key, val string) error

通过租约 注册服务

func (*ServiceReg) RevokeLease

func (this *ServiceReg) RevokeLease() error

撤销租约

type Srv

type Srv struct {
	Name      string
	Url       string
	StartTime string
}

type StructUtil

type StructUtil struct{}

func (StructUtil) CopyStruct2

func (t StructUtil) CopyStruct2(src, dst interface{})

type Val

type Val struct {
	StartTime  string
	UpdateTime string
	Status     int    //状态:1正常 2下线
	Weight     int    //权重:默认为1
	Metatata   string //元数据
	Health     int    //健康状态:1健康 2不健康 3更不健康 ,数值越大越不健康
}

type XjDate

type XjDate time.Time

func InterfaceToDate

func InterfaceToDate(val interface{}) XjDate

func (XjDate) MarshalJSON

func (t XjDate) MarshalJSON() ([]byte, error)

func (*XjDate) Scan

func (t *XjDate) Scan(v interface{}) error

func (XjDate) String

func (t XjDate) String() string

func (XjDate) StringDiy

func (t XjDate) StringDiy(sFormat string) string

func (*XjDate) UnmarshalJSON

func (t *XjDate) UnmarshalJSON(data []byte) (err error)

func (XjDate) Value

func (t XjDate) Value() (driver.Value, error)

type XjTime

type XjTime time.Time

func (XjTime) MarshalJSON

func (t XjTime) MarshalJSON() ([]byte, error)

func (*XjTime) Scan

func (t *XjTime) Scan(v interface{}) error

func (XjTime) String

func (t XjTime) String() string

func (XjTime) StringDiy

func (t XjTime) StringDiy(sFormat string) string

func (*XjTime) UnmarshalJSON

func (t *XjTime) UnmarshalJSON(data []byte) (err error)

func (XjTime) Value

func (t XjTime) Value() (driver.Value, error)

Directories

Path Synopsis
routers
@APIVersion 1.0.0 @Title beego Test API @Description beego has a very cool tools to autogenerate documents for your API @Contact astaxie@gmail.com @TermsOfServiceUrl http://beego.me/ @License Apache 2.0 @LicenseUrl http://www.apache.org/licenses/LICENSE-2.0.html
@APIVersion 1.0.0 @Title beego Test API @Description beego has a very cool tools to autogenerate documents for your API @Contact astaxie@gmail.com @TermsOfServiceUrl http://beego.me/ @License Apache 2.0 @LicenseUrl http://www.apache.org/licenses/LICENSE-2.0.html
routers
@APIVersion 1.0.0 @Title beego Test API @Description beego has a very cool tools to autogenerate documents for your API @Contact astaxie@gmail.com @TermsOfServiceUrl http://beego.me/ @License Apache 2.0 @LicenseUrl http://www.apache.org/licenses/LICENSE-2.0.html
@APIVersion 1.0.0 @Title beego Test API @Description beego has a very cool tools to autogenerate documents for your API @Contact astaxie@gmail.com @TermsOfServiceUrl http://beego.me/ @License Apache 2.0 @LicenseUrl http://www.apache.org/licenses/LICENSE-2.0.html
routers
@APIVersion 1.0.0 @Title beego Test API @Description beego has a very cool tools to autogenerate documents for your API @Contact astaxie@gmail.com @TermsOfServiceUrl http://beego.me/ @License Apache 2.0 @LicenseUrl http://www.apache.org/licenses/LICENSE-2.0.html
@APIVersion 1.0.0 @Title beego Test API @Description beego has a very cool tools to autogenerate documents for your API @Contact astaxie@gmail.com @TermsOfServiceUrl http://beego.me/ @License Apache 2.0 @LicenseUrl http://www.apache.org/licenses/LICENSE-2.0.html
routers
@APIVersion 1.0.0 @Title beego Test API @Description beego has a very cool tools to autogenerate documents for your API @Contact astaxie@gmail.com @TermsOfServiceUrl http://beego.me/ @License Apache 2.0 @LicenseUrl http://www.apache.org/licenses/LICENSE-2.0.html
@APIVersion 1.0.0 @Title beego Test API @Description beego has a very cool tools to autogenerate documents for your API @Contact astaxie@gmail.com @TermsOfServiceUrl http://beego.me/ @License Apache 2.0 @LicenseUrl http://www.apache.org/licenses/LICENSE-2.0.html
routers
@APIVersion 1.0.0 @Title beego Test API @Description beego has a very cool tools to autogenerate documents for your API @Contact astaxie@gmail.com @TermsOfServiceUrl http://beego.me/ @License Apache 2.0 @LicenseUrl http://www.apache.org/licenses/LICENSE-2.0.html
@APIVersion 1.0.0 @Title beego Test API @Description beego has a very cool tools to autogenerate documents for your API @Contact astaxie@gmail.com @TermsOfServiceUrl http://beego.me/ @License Apache 2.0 @LicenseUrl http://www.apache.org/licenses/LICENSE-2.0.html
job
routers
@APIVersion 1.0.0 @Title beego Test API @Description beego has a very cool tools to autogenerate documents for your API @Contact astaxie@gmail.com @TermsOfServiceUrl http://beego.me/ @License Apache 2.0 @LicenseUrl http://www.apache.org/licenses/LICENSE-2.0.html
@APIVersion 1.0.0 @Title beego Test API @Description beego has a very cool tools to autogenerate documents for your API @Contact astaxie@gmail.com @TermsOfServiceUrl http://beego.me/ @License Apache 2.0 @LicenseUrl http://www.apache.org/licenses/LICENSE-2.0.html
log
routers
@APIVersion 1.0.0 @Title beego Test API @Description beego has a very cool tools to autogenerate documents for your API @Contact astaxie@gmail.com @TermsOfServiceUrl http://beego.me/ @License Apache 2.0 @LicenseUrl http://www.apache.org/licenses/LICENSE-2.0.html
@APIVersion 1.0.0 @Title beego Test API @Description beego has a very cool tools to autogenerate documents for your API @Contact astaxie@gmail.com @TermsOfServiceUrl http://beego.me/ @License Apache 2.0 @LicenseUrl http://www.apache.org/licenses/LICENSE-2.0.html
routers
@APIVersion 1.0.0 @Title beego Test API @Description beego has a very cool tools to autogenerate documents for your API @Contact astaxie@gmail.com @TermsOfServiceUrl http://beego.me/ @License Apache 2.0 @LicenseUrl http://www.apache.org/licenses/LICENSE-2.0.html
@APIVersion 1.0.0 @Title beego Test API @Description beego has a very cool tools to autogenerate documents for your API @Contact astaxie@gmail.com @TermsOfServiceUrl http://beego.me/ @License Apache 2.0 @LicenseUrl http://www.apache.org/licenses/LICENSE-2.0.html
reflectdemo
routers
@APIVersion 1.0.0 @Title beego Test API @Description beego has a very cool tools to autogenerate documents for your API @Contact astaxie@gmail.com @TermsOfServiceUrl http://beego.me/ @License Apache 2.0 @LicenseUrl http://www.apache.org/licenses/LICENSE-2.0.html
@APIVersion 1.0.0 @Title beego Test API @Description beego has a very cool tools to autogenerate documents for your API @Contact astaxie@gmail.com @TermsOfServiceUrl http://beego.me/ @License Apache 2.0 @LicenseUrl http://www.apache.org/licenses/LICENSE-2.0.html
routers
@APIVersion 1.0.0 @Title beego Test API @Description beego has a very cool tools to autogenerate documents for your API @Contact astaxie@gmail.com @TermsOfServiceUrl http://beego.me/ @License Apache 2.0 @LicenseUrl http://www.apache.org/licenses/LICENSE-2.0.html
@APIVersion 1.0.0 @Title beego Test API @Description beego has a very cool tools to autogenerate documents for your API @Contact astaxie@gmail.com @TermsOfServiceUrl http://beego.me/ @License Apache 2.0 @LicenseUrl http://www.apache.org/licenses/LICENSE-2.0.html
routers
@APIVersion 1.0.0 @Title beego Test API @Description beego has a very cool tools to autogenerate documents for your API @Contact astaxie@gmail.com @TermsOfServiceUrl http://beego.me/ @License Apache 2.0 @LicenseUrl http://www.apache.org/licenses/LICENSE-2.0.html
@APIVersion 1.0.0 @Title beego Test API @Description beego has a very cool tools to autogenerate documents for your API @Contact astaxie@gmail.com @TermsOfServiceUrl http://beego.me/ @License Apache 2.0 @LicenseUrl http://www.apache.org/licenses/LICENSE-2.0.html

Jump to

Keyboard shortcuts

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