/
util.go
42 lines (34 loc) · 819 Bytes
/
util.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
package firebase
import (
"fmt"
"io"
"net/http"
"github.com/mitchellh/mapstructure"
)
func fetchFirebaseCredentials(url string) ([]byte, error) {
// Send an HTTP GET request to fetch the credentials
resp, err := http.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("HTTP request failed with status code %d", resp.StatusCode)
}
// Read the response body
credentials, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
return credentials, nil
}
func mapToStruct(input map[string]interface{}, output interface{}) error {
cfg := &mapstructure.DecoderConfig{
Metadata: nil,
Result: &output,
TagName: "json",
}
decoder, _ := mapstructure.NewDecoder(cfg)
decoder.Decode(input)
return nil
}