article

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UNKNOW_ERROR                     = 0
	ERR_PRODUCT_NOT_FOUND            = 16050030
	ERR_PRODUCT_MODULE_NOT_FOUND     = 16050033
	ERR_SAAS_DEVICE_BIND_FAIL        = 16050031
	ERR_PRODUCT_APP_FOUND_FAIL       = 16050032
	ERR_REGISTER_DEVICE_LIMIT        = 16050016
	ERR_REGISTER_DEVICE_SINGLE_FAILE = 16050017
	ERR_REGISTER_DEVICE_BATCH_FAILE  = 16050018
)

Variables

View Source
var (
	PrivateHosts = map[string]string{
		"onl":   "http://vpc-eco-iotlink-gateway.sunmi.com",
		"uat":   "http://vpc-eco-iotlink-gateway.uat.sunmi.com",
		"test":  "http://vpc-eco-iotlink-gateway.test.sunmi.com",
		"dev":   "http://vpc-eco-iotlink-gateway.dev.sunmi.com",
		"local": "http://localhost:20080",
	}
	PublicHosts = map[string]string{
		"onl":   "http://api.sunmi.com",
		"uat":   "http://api.uat.sunmi.com",
		"test":  "http://api.test.sunmi.com",
		"dev":   "http://api.dev.sunmi.com",
		"local": "http://localhost:20080",
	}
)
View Source
var DefaultClient = NewClient()
View Source
var ErrIncorrectCode = errors.New("incorrect http status")
View Source
var (
	ErrMap = map[int]string{
		UNKNOW_ERROR:                     "unknow error",
		ERR_PRODUCT_NOT_FOUND:            "product not found(English comment)",
		ERR_PRODUCT_MODULE_NOT_FOUND:     "product module not found",
		ERR_SAAS_DEVICE_BIND_FAIL:        "saas device bind fail",
		ERR_PRODUCT_APP_FOUND_FAIL:       "product app found fail",
		ERR_REGISTER_DEVICE_LIMIT:        "register device limit",
		ERR_REGISTER_DEVICE_SINGLE_FAILE: "register device single faile",
		ERR_REGISTER_DEVICE_BATCH_FAILE:  "Register device batch fail !",
	}
)
View Source
var PubClient = NewPublicClient()

Functions

func ErrProductAppFoundFail

func ErrProductAppFoundFail(msg ...string) *ecode.ErrorV2

code: 16050032 msg: "product app found fail"

func ErrProductModuleNotFound

func ErrProductModuleNotFound(msg ...string) *ecode.ErrorV2

code: 16050033 msg: "product module not found"

func ErrProductNotFound

func ErrProductNotFound(msg ...string) *ecode.ErrorV2

code: 16050030 msg: "product not found(English comment)"

func ErrRegisterDeviceBatchFaile

func ErrRegisterDeviceBatchFaile(msg ...string) *ecode.ErrorV2

code: 16050018 msg: "Register device batch fail !"

func ErrRegisterDeviceLimit

func ErrRegisterDeviceLimit(msg ...string) *ecode.ErrorV2

code: 16050016 msg: "register device limit"

func ErrRegisterDeviceSingleFaile

func ErrRegisterDeviceSingleFaile(msg ...string) *ecode.ErrorV2

code: 16050017 msg: "register device single faile"

func ErrSaasDeviceBindFail

func ErrSaasDeviceBindFail(msg ...string) *ecode.ErrorV2

code: 16050031 msg: "saas device bind fail"

func GetHostUrl

func GetHostUrl(isPrivate bool, envStrs ...string) string

func IsErrProductAppFoundFail

func IsErrProductAppFoundFail(err error) bool

func IsErrProductAppFoundFailDEEP

func IsErrProductAppFoundFailDEEP(err error) bool

func IsErrProductModuleNotFound

func IsErrProductModuleNotFound(err error) bool

func IsErrProductModuleNotFoundDEEP

func IsErrProductModuleNotFoundDEEP(err error) bool

func IsErrProductNotFound

func IsErrProductNotFound(err error) bool

func IsErrProductNotFoundDEEP

func IsErrProductNotFoundDEEP(err error) bool

func IsErrRegisterDeviceBatchFaile

func IsErrRegisterDeviceBatchFaile(err error) bool

func IsErrRegisterDeviceBatchFaileDEEP

func IsErrRegisterDeviceBatchFaileDEEP(err error) bool

func IsErrRegisterDeviceLimit

func IsErrRegisterDeviceLimit(err error) bool

func IsErrRegisterDeviceLimitDEEP

func IsErrRegisterDeviceLimitDEEP(err error) bool

func IsErrRegisterDeviceSingleFaile

func IsErrRegisterDeviceSingleFaile(err error) bool

func IsErrRegisterDeviceSingleFaileDEEP

func IsErrRegisterDeviceSingleFaileDEEP(err error) bool

func IsErrSaasDeviceBindFail

func IsErrSaasDeviceBindFail(err error) bool

func IsErrSaasDeviceBindFailDEEP

func IsErrSaasDeviceBindFailDEEP(err error) bool

func IsUnknowError

func IsUnknowError(err error) bool

func IsUnknowErrorDEEP

func IsUnknowErrorDEEP(err error) bool

func MustCode200

func MustCode200(cli *resty.Client, resp *resty.Response) error

func RegisterAuthServiceHTTPServer

func RegisterAuthServiceHTTPServer(s *gin.Engine, srv AuthServiceHTTPServer)

func RegisterBlogServiceHTTPServer

func RegisterBlogServiceHTTPServer(s *gin.Engine, srv BlogServiceHTTPServer)

func SetAutoValidate

func SetAutoValidate(disable bool, validatErr error, releaseShowDetail bool)

set you error or use api.ErrorBind(diable:是否启用自动validate, 如果启用则返回 defaultValidateErr or 原始错误)

func SetCustomReturn

func SetCustomReturn(ctx *api.Context)

func SetValidateCode added in v1.2.0

func SetValidateCode(code int)

func UnknowError

func UnknowError(msg ...string) *ecode.ErrorV2

code: 0 msg: "unknow error"

Types

type Article

type Article struct {
	// 标题名称上注释
	Title    string `json:"title,omitempty"` // 标题名称右注释
	Content  string `json:"content" binding:"required"`
	AuthorId int32  `json:"author_id,omitempty"`
}

func (*Article) Marshal

func (m *Article) Marshal() ([]byte, error)

func (*Article) MarshalString

func (m *Article) MarshalString() (string, error)

func (*Article) Unmarshal

func (m *Article) Unmarshal(buf []byte) error

func (*Article) UnmarshalString

func (m *Article) UnmarshalString(str string) error

type AuthServiceHTTPClient

type AuthServiceHTTPClient interface {
	// Push发送1 ||商米助手
	// 发送1<br>
	// 发送2<br>
	// > 发送3
	// 发送4
	// `import from json`
	// 这是一个链接 [Markdown语法](https://markdown.com.cn "最好的markdown教程")。
	//
	// | 错误码 | 错误消息 | 错误描述 |
	// | --- | ---- | ---- |
	// | 10207  | ath not match                     | 服务端token不一致      |
	// | 10224  | device not found                  | 设备不存在             |
	// | 10114  | task not found                    | 自动下载密钥任务不存在 |
	// | 10208  | binding key not found             | 绑定密钥不存在         |
	// | 10212  | no available license              | 没有可用license        |
	// | 10213  | license download times not enough | license 下载次数不足   |
	// | 500    |                                   | 程序异常               |
	Push(context.Context, *PushReq, ...calloption.CallOption) (*TResponse[PushReply], error)
	Pull(context.Context, *PushReq, ...calloption.CallOption) (*TResponse[RealResp], error)
	// 测试特殊的返回
	GetOneArticlePure(context.Context, *GetOneArticlePureReq, ...calloption.CallOption) (*GetOneArticlePureResp, error)
	PostOneArticlePure(context.Context, *GetOneArticlePureReq, ...calloption.CallOption) (*GetOneArticlePureResp, error)
}

AuthServiceHTTPClient is the client API for AuthService service.

func NewAuthServiceHTTPClient

func NewAuthServiceHTTPClient(hh *http_request.HttpClient) AuthServiceHTTPClient

type AuthServiceHTTPClientImpl

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

func (*AuthServiceHTTPClientImpl) GetOneArticlePure added in v1.0.9

func (*AuthServiceHTTPClientImpl) PostOneArticlePure added in v1.1.9

func (*AuthServiceHTTPClientImpl) Pull added in v1.0.5

func (*AuthServiceHTTPClientImpl) Push

type AuthServiceHTTPServer

type AuthServiceHTTPServer interface {
	// Push发送1 ||商米助手
	// 发送1<br>
	// 发送2<br>
	// > 发送3
	// 发送4
	// `import from json`
	// 这是一个链接 [Markdown语法](https://markdown.com.cn "最好的markdown教程")。
	//
	// | 错误码 | 错误消息 | 错误描述 |
	// | --- | ---- | ---- |
	// | 10207  | ath not match                     | 服务端token不一致      |
	// | 10224  | device not found                  | 设备不存在             |
	// | 10114  | task not found                    | 自动下载密钥任务不存在 |
	// | 10208  | binding key not found             | 绑定密钥不存在         |
	// | 10212  | no available license              | 没有可用license        |
	// | 10213  | license download times not enough | license 下载次数不足   |
	// | 500    |                                   | 程序异常               |
	Push(*api.Context, *PushReq) (*PushReply, error)
	Pull(*api.Context, *PushReq) (*RealResp, error)
	// 测试特殊的返回
	GetOneArticlePure(*api.Context, *GetOneArticlePureReq) *GetOneArticlePureResp
	PostOneArticlePure(*api.Context, *GetOneArticlePureReq) *GetOneArticlePureResp
}

AuthServiceHTTPServer is the server API for AuthService service.

type BlogServiceHTTPClient

type BlogServiceHTTPClient interface {
	// 获取文章列表
	// 可以读取不多于999个文章列表
	GetArticles(context.Context, *GetArticlesReq, ...calloption.CallOption) (*TResponse[GetArticlesReply], error)
	// 新建文章
	CreateArticle(context.Context, *Article, ...calloption.CallOption) (*TResponse[Article], error)
	// 获取文章详情(TODO get方法还未支持)
	GetOneArticle(context.Context, *GetArticlesReq, ...calloption.CallOption) (*TResponse[GetArticlesReply], error)
}

BlogServiceHTTPClient is the client API for BlogService service.

func NewBlogServiceHTTPClient

func NewBlogServiceHTTPClient(hh *http_request.HttpClient) BlogServiceHTTPClient

func NewClient

func NewClient(strs ...string) BlogServiceHTTPClient

NewClient 使用者也可以根据需要,自己生成newClient方法,然后调用NewBlogHTTPClient方法

func NewPublicClient

func NewPublicClient(strs ...string) BlogServiceHTTPClient

type BlogServiceHTTPClientImpl

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

func (*BlogServiceHTTPClientImpl) CreateArticle

func (c *BlogServiceHTTPClientImpl) CreateArticle(ctx context.Context, req *Article, opts ...calloption.CallOption) (*TResponse[Article], error)

func (*BlogServiceHTTPClientImpl) GetArticles

func (*BlogServiceHTTPClientImpl) GetOneArticle

type BlogServiceHTTPServer

type BlogServiceHTTPServer interface {
	// 获取文章列表
	// 可以读取不多于999个文章列表
	GetArticles(*api.Context, *GetArticlesReq) (*GetArticlesReply, error)
	// 新建文章
	CreateArticle(*api.Context, *Article) (*Article, error)
	// 获取文章详情(TODO get方法还未支持)
	GetOneArticle(*api.Context, *GetArticlesReq) (*GetArticlesReply, error)
}

BlogServiceHTTPServer is the server API for BlogService service.

type GetArticlesReply

type GetArticlesReply struct {
	Total    int64      `json:"total" binding:"required"`
	Articles []*Article `json:"articles"`
}

重要注释1

func (*GetArticlesReply) Marshal

func (m *GetArticlesReply) Marshal() ([]byte, error)

func (*GetArticlesReply) MarshalString

func (m *GetArticlesReply) MarshalString() (string, error)

func (*GetArticlesReply) Unmarshal

func (m *GetArticlesReply) Unmarshal(buf []byte) error

func (*GetArticlesReply) UnmarshalString

func (m *GetArticlesReply) UnmarshalString(str string) error

type GetArticlesReq

type GetArticlesReq struct {
	// 文章标题
	Title string `json:"title" binding:"required"` // 标题名称右注释
	Page  int32  `json:"page,omitempty" binding:"lt=999"`
	// 字段名使用小写下划线的风格,例如 string status_code = 1
	PageSize int32 `json:"page_size,omitempty" binding:"lte=101"`
	// 作者id
	AuthorId int32                    `json:"author_id,omitempty"`
	Email    string                   `json:"email,omitempty" binding:"email"`
	Name     string                   `json:"name,omitempty"`
	Home     *GetArticlesReq_Location `json:"home" binding:"required"`
	TestStr  string                   `json:"test_str" binding:"required"`
}

消息名使用首字母大写驼峰风格(CamelCase),例如message StudentReq { ... }

func (*GetArticlesReq) Marshal

func (m *GetArticlesReq) Marshal() ([]byte, error)

func (*GetArticlesReq) MarshalString

func (m *GetArticlesReq) MarshalString() (string, error)

func (*GetArticlesReq) Unmarshal

func (m *GetArticlesReq) Unmarshal(buf []byte) error

func (*GetArticlesReq) UnmarshalString

func (m *GetArticlesReq) UnmarshalString(str string) error

type GetArticlesReq_Location

type GetArticlesReq_Location struct {
	Lat float64 `json:"lat,omitempty" binding:"lte:90,gte:-90"`
	Lng float64 `json:"lng,omitempty" binding:"gte:-180,lte:180"`
}

type GetOneArticlePureReq added in v1.0.9

type GetOneArticlePureReq struct {
}

func (*GetOneArticlePureReq) Marshal added in v1.0.9

func (m *GetOneArticlePureReq) Marshal() ([]byte, error)

func (*GetOneArticlePureReq) MarshalString added in v1.0.9

func (m *GetOneArticlePureReq) MarshalString() (string, error)

func (*GetOneArticlePureReq) Unmarshal added in v1.0.9

func (m *GetOneArticlePureReq) Unmarshal(buf []byte) error

func (*GetOneArticlePureReq) UnmarshalString added in v1.0.9

func (m *GetOneArticlePureReq) UnmarshalString(str string) error

type GetOneArticlePureResp added in v1.0.9

type GetOneArticlePureResp struct {
	Code    int64                `json:"Code,omitempty"`
	Message string               `json:"Message,omitempty"`
	Data    []*UploadOssdk3RdReq `json:"Data,omitempty"`
}

func (*GetOneArticlePureResp) Marshal added in v1.0.9

func (m *GetOneArticlePureResp) Marshal() ([]byte, error)

func (*GetOneArticlePureResp) MarshalString added in v1.0.9

func (m *GetOneArticlePureResp) MarshalString() (string, error)

func (*GetOneArticlePureResp) Unmarshal added in v1.0.9

func (m *GetOneArticlePureResp) Unmarshal(buf []byte) error

func (*GetOneArticlePureResp) UnmarshalString added in v1.0.9

func (m *GetOneArticlePureResp) UnmarshalString(str string) error

type PushReply

type PushReply struct {
	SdkUrlUuid string `json:"sdk_url_uuid,omitempty"` // 后面的备注
}

上面的备注1 上面的备注2 上面的备注3

func (*PushReply) Marshal

func (m *PushReply) Marshal() ([]byte, error)

func (*PushReply) MarshalString

func (m *PushReply) MarshalString() (string, error)

func (*PushReply) Unmarshal

func (m *PushReply) Unmarshal(buf []byte) error

func (*PushReply) UnmarshalString

func (m *PushReply) UnmarshalString(str string) error

type PushReq

type PushReq struct {
	// name上面的备注
	Name      string `json:"name" binding:"required"`
	PageCount int64  `json:"page_count" binding:"required"`
	DataCount int32  `json:"data_count,omitempty"`
}

这个是PushReq的标题2

func (*PushReq) Marshal

func (m *PushReq) Marshal() ([]byte, error)

func (*PushReq) MarshalString

func (m *PushReq) MarshalString() (string, error)

func (*PushReq) Unmarshal

func (m *PushReq) Unmarshal(buf []byte) error

func (*PushReq) UnmarshalString

func (m *PushReq) UnmarshalString(str string) error

type RealResp

type RealResp struct {
	Data    interface{} `json:"data,omitempty"`
	Code    int32       `json:"code,omitempty"`
	Message string      `json:"message,omitempty"`
}

func (*RealResp) Marshal

func (m *RealResp) Marshal() ([]byte, error)

func (*RealResp) MarshalString

func (m *RealResp) MarshalString() (string, error)

func (*RealResp) Unmarshal

func (m *RealResp) Unmarshal(buf []byte) error

func (*RealResp) UnmarshalString

func (m *RealResp) UnmarshalString(str string) error

type TResponse

type TResponse[T any] struct {
	Code int32  `json:"code"`
	Data *T     `json:"data"`
	Msg  string `json:"msg"`
}

type UploadOssdk3RdReq added in v1.0.9

type UploadOssdk3RdReq struct {
	Operator   string `json:"operator,omitempty"`
	SdkUrlUuid string `json:"sdk_url_uuid,omitempty"`
	SdkOs      string `json:"sdk_os,omitempty"`
	FileName   string `json:"file_name,omitempty"`
}

func (*UploadOssdk3RdReq) Marshal added in v1.0.9

func (m *UploadOssdk3RdReq) Marshal() ([]byte, error)

func (*UploadOssdk3RdReq) MarshalString added in v1.0.9

func (m *UploadOssdk3RdReq) MarshalString() (string, error)

func (*UploadOssdk3RdReq) Unmarshal added in v1.0.9

func (m *UploadOssdk3RdReq) Unmarshal(buf []byte) error

func (*UploadOssdk3RdReq) UnmarshalString added in v1.0.9

func (m *UploadOssdk3RdReq) UnmarshalString(str string) error

Jump to

Keyboard shortcuts

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