-
Notifications
You must be signed in to change notification settings - Fork 0
/
messages.go
52 lines (41 loc) · 1.38 KB
/
messages.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//********************************************************************************************************************//
//
// Copyright (C) 2018 - 2021 J&J Ideenschmiede GmbH <info@jj-ideenschmiede.de>
//
// This file is part of goerecht24.
// All code may be used. Feel free and maybe code something better.
//
// Author: Jonas Kwiedor (aka gowizzard)
//
//********************************************************************************************************************//
package goerecht24
import "encoding/json"
// FetchMessageReturn is to decode the json data
type FetchMessageReturn struct {
Message string `json:"message"`
MessageDe string `json:"message_de"`
Call2Action string `json:"call2action"`
Call2ActionDe string `json:"call2action_de"`
Link string `json:"link"`
Token interface{} `json:"token,omitempty"`
}
// FetchMessage is to fetch a message from eRecht24
func FetchMessage(r Request) (FetchMessageReturn, error) {
// Set config for new request
c := Config{"/message", "GET", nil}
// Send request
response, err := c.Send(r)
if err != nil {
return FetchMessageReturn{}, err
}
// Close request
defer response.Body.Close()
// Decode data
var decode FetchMessageReturn
err = json.NewDecoder(response.Body).Decode(&decode)
if err != nil {
return FetchMessageReturn{}, err
}
// Return data
return decode, err
}