mirror of
				https://github.com/MHSanaei/3x-ui.git
				synced 2025-10-30 03:42:51 +00:00 
			
		
		
		
	
		
			
	
	
		
			25 lines
		
	
	
	
		
			479 B
		
	
	
	
		
			Go
		
	
	
	
	
	
		
		
			
		
	
	
			25 lines
		
	
	
	
		
			479 B
		
	
	
	
		
			Go
		
	
	
	
	
	
|   | package json_util | ||
|  | 
 | ||
|  | import ( | ||
|  | 	"errors" | ||
|  | ) | ||
|  | 
 | ||
|  | type RawMessage []byte | ||
|  | 
 | ||
|  | // MarshalJSON: Customize json.RawMessage default behavior
 | ||
|  | func (m RawMessage) MarshalJSON() ([]byte, error) { | ||
|  | 	if len(m) == 0 { | ||
|  | 		return []byte("null"), nil | ||
|  | 	} | ||
|  | 	return m, nil | ||
|  | } | ||
|  | 
 | ||
|  | // UnmarshalJSON: sets *m to a copy of data.
 | ||
|  | func (m *RawMessage) UnmarshalJSON(data []byte) error { | ||
|  | 	if m == nil { | ||
|  | 		return errors.New("json.RawMessage: UnmarshalJSON on nil pointer") | ||
|  | 	} | ||
|  | 	*m = append((*m)[0:0], data...) | ||
|  | 	return nil | ||
|  | } |