Add general queue
This commit is contained in:
+39
@@ -0,0 +1,39 @@
|
||||
package ersteller
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
type JSONB map[string]interface{}
|
||||
|
||||
func StructToMap(data interface{}) (JSONB, error) {
|
||||
var result JSONB
|
||||
|
||||
// Marshal struct to JSON bytes
|
||||
jsonBytes, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Unmarshal JSON bytes to map
|
||||
err = json.Unmarshal(jsonBytes, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func MapToStruct(data JSONB, result interface{}) error {
|
||||
// Marshal map to JSON bytes
|
||||
jsonBytes, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Unmarshal JSON bytes to struct
|
||||
err = json.Unmarshal(jsonBytes, result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user