Documentation
¶
Index ¶
- Constants
- Variables
- func AddMonth(t time.Time, m int) time.Time
- func ApplicationKey(application string) string
- func BusinessValidator(t Business) error
- func ChSafeClose[T any](ch chan T) (justClosed bool)
- func ChSafeSend[T any](ch chan T, value T) (closed bool)
- func ConvertBytes2String(b []byte) string
- func ConvertSliceToMap[T any, K comparable](arr []T, f func(T) (K, T, bool)) (data map[K]T)
- func ConvertString2Bytes(s string) (b []byte)
- func CreateDirectoryIfNotExist(d string) error
- func CreateRequest(user *User) *resty.Request
- func FastRequest[T ResponseVerifiable](url string, method RequestMethod, params ...any) (data T, err error)
- func GetCaller(skip int) *runtime.Frame
- func GetKoanf() *koanf.Koanf
- func GetTrueBits[T PositiveNumber](num T, max int) (bits []int)
- func LoadConfigure[T Configurable](cfg T, cf string, defaultConfig []byte) (err error)
- func NewBuffer() *bytes.Buffer
- func Or[T any](condition bool, yes T, no T) T
- func Post[T any](url string, user *User, payload any, params ...any) (data T, err error)
- func ReleaseBuffer(buf *bytes.Buffer)
- func RemoveSliceDuplicate[T comparable](items []T) (list []T)
- type AurResponse
- type Battery
- type BatteryBrand
- type Bool
- type Business
- func (b Business) BatteryNeed() bool
- func (b Business) MarshalGQL(w io.Writer)
- func (b *Business) Scan(src interface{}) error
- func (b Business) String() string
- func (b Business) Text() string
- func (b *Business) UnmarshalGQL(val interface{}) error
- func (b Business) Value() (driver.Value, error)
- func (Business) Values() []string
- type Byter
- type BytesCallback
- type CabinetBrand
- type Configurable
- type Configure
- func (c *Configure) GetApiAddress() string
- func (c *Configure) GetApplication() string
- func (c *Configure) GetCacheKey(key string) string
- func (c *Configure) GetEnvironment() Environment
- func (c *Configure) GetKeyPrefix() string
- func (c *Configure) GetLoggerName() string
- func (c *Configure) SetEnvironment(env Environment)
- func (c *Configure) SetKeyPrefix(prefix string)
- type DefaultJSONSerializer
- type Environment
- type Geometry
- func (g *Geometry) Bytes() (data []byte)
- func (g *Geometry) Distance(g2 *Geometry) float64
- func (g *Geometry) FromBytes(data []byte)
- func (g *Geometry) Scan(val interface{}) error
- func (g *Geometry) String() string
- func (g Geometry) Value() (driver.Value, error)
- func (g *Geometry) WGS84toGCJ02() *Geometry
- type Logger
- type PointInt
- type PositiveNumber
- type RequestHeader
- type RequestMethod
- type Response
- type ResponseVerifiable
- type User
- type UserType
- type VoidFunc
- type ZapLogger
Constants ¶
const ( HeaderUserID = "X-User-ID" HeaderUserType = "X-User-Type" )
Variables ¶
var ( Newline = []byte{10} // \n Space = []byte{32} // DoubleQuote = []byte{34} // " SingleQuote = []byte{39} // ' Comma = []byte{44} // , Hyphen = []byte{45} // - Period = []byte{46} // . Colon = []byte{58} // : Equal = []byte{61} // = LeftSquareBracket = []byte{91} // [ RightSquareBracket = []byte{93} // ] LeftBracket = []byte{40} // ( RightBracket = []byte{41} // ) LeftCurlyBracket = []byte{123} // { RightCurlyBracket = []byte{125} // } )
var ( ErrorData = errors.New("数据错误") ErrorConfig = errors.New("配置获取失败") ErrorLoginExpired = errors.New("登录超时") ErrorForbidden = errors.New("禁止访问") ErrorInvaildCheckSum = errors.New("数据和校验失败") ErrorNotFound = errors.New("未找到资源") ErrorExpired = errors.New("已过期") ErrorBadRequest = errors.New("请求参数错误") ErrorInternalServer = errors.New("未知错误") ErrorUserRequired = errors.New("需要用户信息") ErrorPermission = errors.New("非法请求") ErrorIncompletePacket = errors.New("incomplete packet") // 数据包不完整 ErrorIncorrectPacket = errors.New("消息错误") ErrorParamValidateFailed = errors.New("数据校验失败") ErrorMaintain = errors.New("正在唤醒, 请稍后") ErrorCabinetBrand = errors.New("电柜品牌错误") ErrorCabinetSerialRequired = errors.New("电柜编码不存在") ErrorCabinetBrandRequired = errors.New("电柜型号不存在") ErrorCabinetNotFound = errors.New("电柜未找到") ErrorCabinetOffline = errors.New("电柜离线") ErrorCabinetInitializing = errors.New("电柜初始化中") ErrorCabinetAbnormal = errors.New("电柜状态异常") ErrorCabinetClientNotFound = errors.New("未找到在线电柜") ErrorCabinetNoFully = errors.New("无可换电池") ErrorCabinetNoEmpty = errors.New("无空仓位") ErrorCabinetBusy = errors.New("电柜忙") ErrorCabinetControlParam = errors.New("电柜控制参数错误") ErrorCabinetDoorOpened = errors.New("有开启中的仓门") ErrorScanNotExist = errors.New("任务不存在") ErrorScanExpired = errors.New("任务已过期") ErrorExchangeCannot = errors.New("该仓位不满足换电条件") ErrorExchangeFailed = errors.New("换电失败") ErrorExchangeBatteryLost = errors.New("电池未放入") ErrorExchangeBatteryExist = errors.New("电池未取走") ErrorBinOpened = errors.New("仓门已是开启状态") ErrorBinDisabled = errors.New("仓位已是禁用状态") ErrorBinEnabled = errors.New("仓位已是启用状态") ErrorBinNotFound = errors.New("仓位未找到") ErrorBinOrdinalRequired = errors.New("仓位序号不存在") ErrorBinNotEnough = errors.New("无足够数量的仓位") ErrorBinNotUsable = errors.New("仓位不可用") ErrorOperateTimeout = errors.New("操作超时") ErrorOperateNoStep = errors.New("无后续操作") ErrorOperateCommand = errors.New("未知的操作指令") ErrorBusiness = errors.New("业务类型错误") ErrorBusinessUnable = errors.New("无法办理该业务") ErrorBatteryPutin = errors.New("放入电池编号不匹配") ErrorBatteryNotEnough = errors.New("电池数量不足") ErrorBatterySN = errors.New("电池编码错误") ErrorBatteryNotFound = errors.New("未找到当前绑定的电池信息") )
var (
BatteryModelXC = map[string]string{
"08": "72V30AH",
"11": "72V35AH",
"12": "60V30AH",
"16": "72V35AH",
"17": "60V45AH",
}
)
var (
RiderBusiness = []Business{BusinessActive, BusinessPause, BusinessContinue, BusinessUnsubscribe, BusinessExchangeReopen}
)
Functions ¶
func ApplicationKey ¶
func BusinessValidator ¶
func ChSafeClose ¶
func ChSafeSend ¶
func ConvertBytes2String ¶
func ConvertSliceToMap ¶
func ConvertSliceToMap[T any, K comparable](arr []T, f func(T) (K, T, bool)) (data map[K]T)
func ConvertString2Bytes ¶
func CreateDirectoryIfNotExist ¶
CreateDirectoryIfNotExist 若目录不存在则创建
func CreateRequest ¶
func CreateRequest(user *User) *resty.Request
func FastRequest ¶
func FastRequest[T ResponseVerifiable](url string, method RequestMethod, params ...any) (data T, err error)
func GetTrueBits ¶
func GetTrueBits[T PositiveNumber](num T, max int) (bits []int)
func LoadConfigure ¶
func LoadConfigure[T Configurable](cfg T, cf string, defaultConfig []byte) (err error)
func ReleaseBuffer ¶
func RemoveSliceDuplicate ¶
func RemoveSliceDuplicate[T comparable](items []T) (list []T)
Types ¶
type AurResponse ¶
type AurResponse[T any] struct { Code int `json:"code"` Message string `json:"message,omitempty"` Data T `json:"data,omitempty"` }
func (*AurResponse[T]) Verify ¶
func (r *AurResponse[T]) Verify() error
type Battery ¶
type Battery struct { SN string `json:"sn"` // 电池编号 Brand BatteryBrand `json:"brand"` // 电池厂家 Model string `json:"model"` // 电池型号 }
type BatteryBrand ¶
type BatteryBrand string
const ( BatteryBrandUnknown BatteryBrand = "UNKNOWN" // 未知 BatteryBrandXC BatteryBrand = "XC" // 星创电池 BatteryBrandTB BatteryBrand = "TB" // 拓邦电池 )
func (BatteryBrand) RpcName ¶
func (b BatteryBrand) RpcName() string
func (*BatteryBrand) Scan ¶
func (b *BatteryBrand) Scan(src interface{}) error
func (BatteryBrand) String ¶
func (b BatteryBrand) String() string
type Business ¶
type Business string
Business 全部业务类型
const ( BusinessOperate Business = "operate" // 运维操作 BusinessExchange Business = "exchange" // 换电 BusinessActive Business = "active" // 激活 BusinessPause Business = "pause" // 寄存 BusinessContinue Business = "continue" // 取消寄存 BusinessUnsubscribe Business = "unsubscribe" // 退订 BusinessExchangeReopen Business = "reopen" // 换电重复开仓 )
func (Business) MarshalGQL ¶
MarshalGQL implements graphql.Marshaler interface.
func (*Business) UnmarshalGQL ¶
UnmarshalGQL implements graphql.Unmarshaler interface.
type BytesCallback ¶
type BytesCallback func(b []byte)
type CabinetBrand ¶
type CabinetBrand string
const ( CabinetBrandUnknown CabinetBrand = "UNKNOWN" CabinetBrandKaixin CabinetBrand = "KAIXIN" CabinetBrandYundong CabinetBrand = "YUNDONG" CabinetBrandTuobang CabinetBrand = "TUOBANG" CabinetBrandXiliulouServer CabinetBrand = "XILIULOUSERV" // 西六楼服务器版 )
func (CabinetBrand) Name ¶
func (b CabinetBrand) Name() string
func (CabinetBrand) RpcName ¶
func (b CabinetBrand) RpcName() string
func (*CabinetBrand) Scan ¶
func (b *CabinetBrand) Scan(src interface{}) error
func (CabinetBrand) String ¶
func (b CabinetBrand) String() string
type Configurable ¶
type Configurable interface { GetApplication() string GetLoggerName() string GetEnvironment() Environment SetEnvironment(env Environment) GetApiAddress() string SetKeyPrefix(prefix string) GetKeyPrefix() string GetCacheKey(key string) string }
type Configure ¶
type Configure struct { Application string Environment Environment LoggerName string Api struct { Bind string BodyLimit string RateLimit float64 } Redis struct { Address string Username string Password string DB int `koanf:"db"` } // contains filtered or unexported fields }
func (*Configure) GetApiAddress ¶
func (*Configure) GetApplication ¶
func (*Configure) GetCacheKey ¶
func (*Configure) GetEnvironment ¶
func (c *Configure) GetEnvironment() Environment
func (*Configure) GetKeyPrefix ¶
func (*Configure) GetLoggerName ¶
func (*Configure) SetEnvironment ¶
func (c *Configure) SetEnvironment(env Environment)
func (*Configure) SetKeyPrefix ¶
type DefaultJSONSerializer ¶
type DefaultJSONSerializer struct{}
DefaultJSONSerializer implements JSON encoding using encoding/jsoniter.
func (DefaultJSONSerializer) Deserialize ¶
func (d DefaultJSONSerializer) Deserialize(c echo.Context, i interface{}) error
Deserialize reads a JSON from a request body and converts it into an interface.
func (DefaultJSONSerializer) Serialize ¶
func (d DefaultJSONSerializer) Serialize(c echo.Context, i interface{}, indent string) error
Serialize converts an interface into a json and writes it to the response. You can optionally use the indent parameter to produce pretty JSONs.
type Environment ¶
type Environment string
const ( Production Environment = "production" Development Environment = "development" )
func (Environment) IsDevelopment ¶
func (e Environment) IsDevelopment() bool
func (Environment) String ¶
func (e Environment) String() string
func (Environment) UpperString ¶
func (e Environment) UpperString() string
type Geometry ¶
Geometry 坐标 https://github.com/go-pg/pg/issues/829#issuecomment-505882885
func NewGeometry ¶
func (*Geometry) Distance ¶
Distance function returns the distance (in meters) between two points of
a given longitude and latitude relatively accurately (using a spherical approximation of the Earth) through the Haversin Distance Formula for great arc distance on a sphere with accuracy for small distances
point coordinates are supplied in degrees and converted into rad. in the func
distance returned is METERS!!!!!! http://en.wikipedia.org/wiki/Haversine_formula https://gist.github.com/cdipaolo/d3f8db3848278b49db68
func (*Geometry) WGS84toGCJ02 ¶
type Logger ¶
type Logger interface { Trace(args ...interface{}) Debug(args ...interface{}) Info(args ...any) Warn(args ...interface{}) Error(args ...any) Fatal(args ...interface{}) Tracef(format string, args ...interface{}) Debugf(format string, args ...interface{}) Infof(format string, args ...any) Warnf(format string, args ...interface{}) Errorf(format string, args ...any) Fatalf(format string, args ...interface{}) }
type PositiveNumber ¶
type RequestHeader ¶
type RequestMethod ¶
type RequestMethod string
const ( RequestMethodGet RequestMethod = "Get" RquestMethodPost RequestMethod = "POST" )
func (RequestMethod) String ¶
func (r RequestMethod) String() string
type Response ¶
type ResponseVerifiable ¶
type ResponseVerifiable interface {
Verify() error
}
type User ¶
type User struct { Type UserType `json:"type" validate:"required"` // 用户类别 ID string `json:"id" validate:"required"` // 用户ID(通常是电话), 电柜的时候使用电柜ID }
func (*User) MarshalLogObject ¶
func (u *User) MarshalLogObject(encoder zapcore.ObjectEncoder) error
type UserType ¶
type UserType string
const ( UserTypeUnknown UserType = "unknown" // 未知 UserTypeCabinet UserType = "cabinet" // 电柜 UserTypeManager UserType = "manager" // 后台 UserTypeEmployee UserType = "employee" // 员工 UserTypeRider UserType = "rider" // 骑手 UserTypeAgent UserType = "agent" // 代理 UserTypeMaintainer UserType = "maintainer" // 运维 )
type ZapLogger ¶
type ZapLogger interface { Fatal(msg string, fields ...zap.Field) Panic(msg string, fields ...zap.Field) DPanic(msg string, fields ...zap.Field) Error(msg string, fields ...zap.Field) Warn(msg string, fields ...zap.Field) Info(msg string, fields ...zap.Field) Debug(msg string, fields ...zap.Field) Infof(format string, args ...interface{}) Errorf(format string, args ...interface{}) GetLogger() *zap.Logger }