Conditions | 4 |
Total Lines | 24 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | package model |
||
31 | func (b *Booking) UnmarshalJSON(data []byte) error { |
||
32 | var buffer struct { |
||
33 | RoomId int `json:"room_id"` |
||
34 | DateStart string `json:"date_start"` |
||
35 | DateEnd string `json:"date_end"` |
||
36 | } |
||
37 | if err := json.Unmarshal(data, &buffer); err != nil { |
||
38 | return err |
||
39 | } |
||
40 | |||
41 | dateStart, err := time.Parse(DateFormat, buffer.DateStart) |
||
42 | if err != nil { |
||
43 | return errors.New("bad date_start") |
||
44 | } |
||
45 | dateEnd, err := time.Parse(DateFormat, buffer.DateEnd) |
||
46 | if err != nil { |
||
47 | return errors.New("bad date_end") |
||
48 | } |
||
49 | |||
50 | b.RoomId = buffer.RoomId |
||
51 | b.DateStart = dateStart |
||
52 | b.DateEnd = dateEnd |
||
53 | |||
54 | return nil |
||
55 | } |
||
56 |