common

package
v0.0.0-...-5870b03 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: GPL-3.0 Imports: 19 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DEV  = "dev"
	TEST = "test"
	PROD = "prod"
)
View Source
const GrpcHTTPTraceIDKey = "Trace_id"
View Source
const GrpcTraceIDKey = "trace_id"

Variables

View Source
var (
	APPPATH = GetAppPath()
	APPNAME = GetAppName()
)
View Source
var (
	//VERSION 版本
	//通过go build -ldflags "-X github.com/hsyan2008/hfw/common.VERSION=v0.2"赋值
	//也可以通过环境变量赋值,此方式优先
	VERSION string = "v0.1"
	//ENVIRONMENT 环境
	ENVIRONMENT string

	//通过go build -ldflags "-X github.com/hsyan2008/hfw/common.GOPATH=~/go"赋值
	GOPATH string = os.Getenv("GOPATH")

	PID         = os.Getpid()
	HOSTNAME, _ = os.Hostname()
)

Functions

func AddErrorMap

func AddErrorMap(errNo int64, errMsg string)

func ConvertToInt

func ConvertToInt(v interface{}) int

func GetAddrForListen

func GetAddrForListen(addr string) (string, error)

监听127.0.0.1用于限定内部访问,完整的返回 其他情况用于注册服务,只返回端口部分

func GetAppName

func GetAppName() string

func GetAppPath

func GetAppPath() string

func GetCaller

func GetCaller(depth int) (file string, line int)

func GetClientIP

func GetClientIP(r *http.Request) string

获取客户端ip

func GetEnv

func GetEnv() string

func GetErrorMap

func GetErrorMap(errNo int64) string

func GetHostIP

func GetHostIP(interfaceName string) (host string, err error)

获取本机ip,可以指定网卡名字

func GetHostName

func GetHostName() string

func GetPid

func GetPid() int

func GetPureUUID

func GetPureUUID(oldS ...string) (s string)

func GetRegisterAddress

func GetRegisterAddress(interfaceName, address string) (host string, port int, err error)

如果address是完整的ip:port,则返回 否则取本机的ip地址,加上address的端口

func GetServerAddr

func GetServerAddr(listendAddr, addr string) string

取listend的端口,加上配置的host(可能为空)

func GetStack

func GetStack() []byte

用于打印panic时的堆栈

func GetTraceIDFromIncomingContext

func GetTraceIDFromIncomingContext(ctx context.Context) string

func GetTraceIDFromOutgoingContext

func GetTraceIDFromOutgoingContext(ctx context.Context) string

func GetTraceIDFromRequest

func GetTraceIDFromRequest(r *http.Request) (traceID string)

func GetVersion

func GetVersion() string

func IsDevEnv

func IsDevEnv() bool

func IsDir

func IsDir(filepath string) bool

IsDir ...

func IsExist

func IsExist(filepath string) bool

IsExist ...

func IsGoRun

func IsGoRun() bool

func IsGoTest

func IsGoTest() bool

func IsInStringArray

func IsInStringArray(val string, arr []string) bool

func IsProdEnv

func IsProdEnv() bool

func IsTestEnv

func IsTestEnv() bool

func Max

func Max(i int, j ...int) int

Max ..

func Md5

func Md5(str string) string

Md5 ..

func Min

func Min(i int, j ...int) int

Min ..

func ParseFlag

func ParseFlag() (err error)

func SetErrorMap

func SetErrorMap(m map[int64]string)

func ToOsCode

func ToOsCode(text string) string

转换为当前操作系统支持的编码 linux和mac为utf8 win为GBK

func UtfToUnicode

func UtfToUnicode(d []byte) (reader *bytes.Buffer, err error)

把中文转成\u8981之类的unicode编码 参考http://blog.cyeam.com/json/2014/08/04/go_json utf8包

func Uuid

func Uuid() string

Types

type RespErr

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

func NewRespErr

func NewRespErr(errNo int64, i interface{}) (respErr *RespErr)

记录调用本函数的位置

func (*RespErr) Err

func (respErr *RespErr) Err() error

func (*RespErr) ErrMsg

func (respErr *RespErr) ErrMsg() string

func (*RespErr) ErrNo

func (respErr *RespErr) ErrNo() int64

func (*RespErr) Error

func (respErr *RespErr) Error() string

func (*RespErr) String

func (respErr *RespErr) String() string

func (*RespErr) Unwrap

func (respErr *RespErr) Unwrap() error

type Response

type Response struct {
	ErrNo   int64       `json:"err_no"`
	ErrMsg  string      `json:"err_msg"`
	Results interface{} `json:"results"`
}

Response ..

Jump to

Keyboard shortcuts

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