all adjustments
This commit is contained in:
@@ -7,14 +7,14 @@ import (
|
||||
type Inbound struct {
|
||||
Id uint `json:"id" form:"id" gorm:"primaryKey;autoIncrement"`
|
||||
Type string `json:"type" form:"type"`
|
||||
Tag string `json:"tag" form:"tag"`
|
||||
Tag string `json:"tag" form:"tag" gorm:"unique"`
|
||||
|
||||
// Foreign key to tls table
|
||||
TlsId uint `json:"tls_id" form:"tls_id"`
|
||||
Tls *Tls `json:"tls" form:"tls" gorm:"foreignKey:TlsId;references:Id"`
|
||||
|
||||
Addrs json.RawMessage `json:"addrs" form:"addrs"`
|
||||
OutJson json.RawMessage `json:"outJson" form:"outJson"`
|
||||
OutJson json.RawMessage `json:"out_json" form:"out_json"`
|
||||
Options json.RawMessage `json:"-" form:"-"`
|
||||
}
|
||||
|
||||
@@ -26,10 +26,10 @@ func (i *Inbound) UnmarshalJSON(data []byte) error {
|
||||
}
|
||||
|
||||
// Extract fixed fields and store the rest in Options
|
||||
if val, exists := raw["id"].(uint); exists {
|
||||
i.Id = val
|
||||
delete(raw, "id")
|
||||
if val, exists := raw["id"].(float64); exists {
|
||||
i.Id = uint(val)
|
||||
}
|
||||
delete(raw, "id")
|
||||
i.Type, _ = raw["type"].(string)
|
||||
delete(raw, "type")
|
||||
i.Tag, _ = raw["tag"].(string)
|
||||
@@ -48,8 +48,8 @@ func (i *Inbound) UnmarshalJSON(data []byte) error {
|
||||
delete(raw, "addrs")
|
||||
|
||||
// OutJson
|
||||
i.OutJson, _ = json.MarshalIndent(raw["outJson"], "", " ")
|
||||
delete(raw, "outJson")
|
||||
i.OutJson, _ = json.MarshalIndent(raw["out_json"], "", " ")
|
||||
delete(raw, "out_json")
|
||||
|
||||
// Remaining fields
|
||||
i.Options, err = json.MarshalIndent(raw, "", " ")
|
||||
@@ -79,3 +79,25 @@ func (i Inbound) MarshalJSON() ([]byte, error) {
|
||||
|
||||
return json.Marshal(combined)
|
||||
}
|
||||
|
||||
func (i Inbound) MarshalFull() (*map[string]interface{}, error) {
|
||||
combined := make(map[string]interface{})
|
||||
combined["id"] = i.Id
|
||||
combined["type"] = i.Type
|
||||
combined["tag"] = i.Tag
|
||||
combined["tls_id"] = i.TlsId
|
||||
combined["addrs"] = i.Addrs
|
||||
combined["out_json"] = i.OutJson
|
||||
|
||||
if i.Options != nil {
|
||||
var restFields map[string]json.RawMessage
|
||||
if err := json.Unmarshal(i.Options, &restFields); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for k, v := range restFields {
|
||||
combined[k] = v
|
||||
}
|
||||
}
|
||||
return &combined, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user