-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathget.go
More file actions
39 lines (32 loc) · 883 Bytes
/
get.go
File metadata and controls
39 lines (32 loc) · 883 Bytes
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
package events
import (
"fmt"
"net/http"
"os"
"github.com/acmcsufoss/api.acmcsuf.com/internal/cli/client"
"github.com/acmcsufoss/api.acmcsuf.com/internal/cli/config"
"github.com/acmcsufoss/api.acmcsuf.com/utils"
"github.com/spf13/cobra"
)
var GetEvent = &cobra.Command{
Use: "get",
Short: "Get one or all events",
Run: func(cmd *cobra.Command, args []string) {
id, _ := cmd.Flags().GetString("id")
getEvents(id, config.Cfg)
},
}
func init() {
GetEvent.Flags().String("id", "", "Get a specific event")
}
func getEvents(id string, cfg *config.Config) {
getUrl := config.GetBaseURL(cfg).JoinPath("v1", "events", id)
if body, err := client.SendRequestAndReadResponse(getUrl, false, http.MethodGet, nil); err != nil {
fmt.Fprintln(os.Stderr, "Error:", err)
if body != nil {
utils.PrettyPrintJSONErr(body)
}
} else {
utils.PrettyPrintJSON(body)
}
}