mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-11 13:53:35 +08:00
实现HTTP部分功能
This commit is contained in:
27
internal/db/models/sys_event_model_ext.go
Normal file
27
internal/db/models/sys_event_model_ext.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// 解码事件
|
||||
func (this *SysEvent) DecodeEvent() (EventInterface, error) {
|
||||
// 解析数据类型
|
||||
t, isOk := eventTypeMapping[this.Type]
|
||||
if !isOk {
|
||||
return nil, errors.New("can not found event type '" + this.Type + "'")
|
||||
}
|
||||
ptr := reflect.New(t).Interface().(EventInterface)
|
||||
|
||||
// 解析参数
|
||||
if IsNotNull(this.Params) {
|
||||
err := json.Unmarshal([]byte(this.Params), ptr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return ptr, nil
|
||||
}
|
||||
Reference in New Issue
Block a user