adapter

package module
v0.0.0-...-617738d Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2025 License: MIT Imports: 29 Imported by: 0

README

Auroraride Adapter

各项服务绑定端口说明

端口基本规则:
  1. 4位数字
  2. 前两位为服务代号,后两位为 端口代号
  3. 测试环境端口一律加13000, 例如: 5010 -> 18010, 16510 -> 29510
  4. 电柜端口统一为
    1. 智能柜: 165xx
    2. 非智能柜: 167xx
业务及代号
业务 正式代号 测试代号 备注
aurservd 50 180 主业务
kxcab 51 181 凯信智能柜
xcbms 52 182 星创智能电池
ydcab 53 183 云动电柜
tbcab 54 184 拓邦电柜
tbbms 55 185 拓邦电池
kxnicab 56 186 凯信非智能柜
xllscab 57 187 西六楼智能柜-服务端对接
端口代号
端口类型 代号
TCP / HTTP 1x, 2x
gRPC 3x
端口列表
服务 代码 TCP API gRPC exhook
凯信智能柜 kxcab 16510 5110 5131
**「测试」**凯信智能柜 kxcab-dev 29710 18610 18631
凯信非智能柜 kxnicab 16720 5610 5631
**「测试」**凯信非智能柜 kxnicab-dev 29520 18110 18131
拓邦智能柜 tbcab 16520 5410 5431
**「测试」**拓邦智能柜 tbcab-dev 29520 18410 18431
云动非智能柜 ydcab 16710 5310 5331
**「测试」**云动非智能柜 ydcab-dev 29710 18310 18331
星创BMS xcbms 5210 5231 5230
西六楼智能柜 - API对接 xlls 16530 (http) 5710 5731
**「测试」**西六楼智能柜 - API对接 xlls-dev 29530 (http) 18710 18731

日志数据库

ClickHouse

日志库

zap

MQTT

字节

消息

gRPC

Documentation

Index

Constants

View Source
const (
	HeaderUserID   = "X-User-ID"
	HeaderUserType = "X-User-Type"
)

Variables

View Source
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} // }
)
View Source
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("未找到当前绑定的电池信息")
)
View Source
var (
	BatteryModelXC = map[string]string{
		"08": "72V30AH",
		"11": "72V35AH",
		"12": "60V30AH",
		"16": "72V35AH",
		"17": "60V45AH",
	}
)

Functions

func AddMonth

func AddMonth(t time.Time, m int) time.Time

func ApplicationKey

func ApplicationKey(application string) string

func BusinessValidator

func BusinessValidator(t Business) error

func ChSafeClose

func ChSafeClose[T any](ch chan T) (justClosed bool)

func ChSafeSend

func ChSafeSend[T any](ch chan T, value T) (closed bool)

func ConvertBytes2String

func ConvertBytes2String(b []byte) string

func ConvertSliceToMap

func ConvertSliceToMap[T any, K comparable](arr []T, f func(T) (K, T, bool)) (data map[K]T)

func ConvertString2Bytes

func ConvertString2Bytes(s string) (b []byte)

func CreateDirectoryIfNotExist

func CreateDirectoryIfNotExist(d string) error

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 GetCaller

func GetCaller(skip int) *runtime.Frame

func GetKoanf

func GetKoanf() *koanf.Koanf

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 NewBuffer

func NewBuffer() *bytes.Buffer

func Or

func Or[T any](condition bool, yes T, no T) T

func Post

func Post[T any](url string, user *User, payload any, params ...any) (data T, err error)

func ReleaseBuffer

func ReleaseBuffer(buf *bytes.Buffer)

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"` // 电池型号
}

func ParseBatterySN

func ParseBatterySN(sn string) (bat Battery, err error)

ParseBatterySN 解析电池编号

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

func (BatteryBrand) Value

func (b BatteryBrand) Value() (driver.Value, error)

type Bool

type Bool bool
const (
	True  Bool = true
	False Bool = false
)

func (Bool) String

func (b Bool) 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) BatteryNeed

func (b Business) BatteryNeed() bool

BatteryNeed 业务是否需要原本电池

func (Business) MarshalGQL

func (b Business) MarshalGQL(w io.Writer)

MarshalGQL implements graphql.Marshaler interface.

func (*Business) Scan

func (b *Business) Scan(src interface{}) error

func (Business) String

func (b Business) String() string

func (Business) Text

func (b Business) Text() string

func (*Business) UnmarshalGQL

func (b *Business) UnmarshalGQL(val interface{}) error

UnmarshalGQL implements graphql.Unmarshaler interface.

func (Business) Value

func (b Business) Value() (driver.Value, error)

func (Business) Values

func (Business) Values() []string

type Byter

type Byter interface {
	Bytes() (data []byte)
	FromBytes(data []byte)
}

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

func (CabinetBrand) Value

func (b CabinetBrand) Value() (driver.Value, error)

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 (c *Configure) GetApiAddress() string

func (*Configure) GetApplication

func (c *Configure) GetApplication() string

func (*Configure) GetCacheKey

func (c *Configure) GetCacheKey(key string) string

func (*Configure) GetEnvironment

func (c *Configure) GetEnvironment() Environment

func (*Configure) GetKeyPrefix

func (c *Configure) GetKeyPrefix() string

func (*Configure) GetLoggerName

func (c *Configure) GetLoggerName() string

func (*Configure) SetEnvironment

func (c *Configure) SetEnvironment(env Environment)

func (*Configure) SetKeyPrefix

func (c *Configure) SetKeyPrefix(prefix string)

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

type Geometry struct {
	Lng float64 `json:"lng"`
	Lat float64 `json:"lat"`
}

Geometry 坐标 https://github.com/go-pg/pg/issues/829#issuecomment-505882885

func NewGeometry

func NewGeometry(b []byte) (geom *Geometry)

func (*Geometry) Bytes

func (g *Geometry) Bytes() (data []byte)

func (*Geometry) Distance

func (g *Geometry) Distance(g2 *Geometry) float64

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) FromBytes

func (g *Geometry) FromBytes(data []byte)

func (*Geometry) Scan

func (g *Geometry) Scan(val interface{}) error

func (*Geometry) String

func (g *Geometry) String() string

func (Geometry) Value

func (g Geometry) Value() (driver.Value, error)

func (*Geometry) WGS84toGCJ02

func (g *Geometry) WGS84toGCJ02() *Geometry

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 PointInt

type PointInt *int

type PositiveNumber

type PositiveNumber interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
}

type RequestHeader

type RequestHeader struct {
	Key   string
	Value string
}

type RequestMethod

type RequestMethod string
const (
	RequestMethodGet RequestMethod = "Get"
	RquestMethodPost RequestMethod = "POST"
)

func (RequestMethod) String

func (r RequestMethod) String() string

type Response

type Response[T any] struct {
	Code    int    `json:"code"`
	Message string `json:"message,omitempty"`
	Data    T      `json:"data,omitempty"`
}

func (*Response[T]) Verify

func (r *Response[T]) Verify() error

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

func (*User) String

func (u *User) String() string

func (*User) ZapField

func (u *User) ZapField() zap.Field

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" // 运维
)

func (*UserType) Scan

func (t *UserType) Scan(src interface{}) error

func (UserType) String

func (t UserType) String() string

func (UserType) Value

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

type VoidFunc

type VoidFunc func()

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
}

Directories

Path Synopsis
cmd
defs
ent
rpc
pb

Jump to

Keyboard shortcuts

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