-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate.go
More file actions
51 lines (40 loc) · 1.18 KB
/
create.go
File metadata and controls
51 lines (40 loc) · 1.18 KB
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
package phant
import (
"strings"
)
// CreateResponse will hold information about a created stream
type CreateResponse struct {
Success bool `json:"success"`
Message string `json:"message"`
PublicKey string `json:"publickey"`
PrivateKey string `json:"privateKey"`
DeleteKey string `json:"deleteKey"`
}
// CreateStream creates a stream
func CreateStream(title, description string, tags []string, fields []string, hidden bool) (CreateResponse, error) {
var hiddenFormFalue = "0"
if hidden == true {
hiddenFormFalue = "1"
}
bodyReader := strings.NewReader(convertMapStringStringToURLValues(map[string]string{
"title": title,
"description": description,
"hidden": hiddenFormFalue,
"tags": strings.Join(tags, ","),
"fields": strings.Join(fields, ","),
"check": "",
}).Encode())
var createRes = CreateResponse{}
req, err := createHTTPRequest("POST", defaultEndpointPrefix+"streams", bodyReader)
if err != nil {
return createRes, err
}
_, err = decodeJsonAndClose(req, &createRes)
if err != nil {
return createRes, err
}
if createRes.Success == false {
return createRes, standardError{createRes.Message}
}
return createRes, nil
}