Created
March 22, 2022 05:50
-
-
Save R167/9347a9175247bc86a41ef1612413d42a to your computer and use it in GitHub Desktop.
Test golang bookmarks SDK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"encoding/json" | |
"github.com/slack-go/slack" | |
) | |
const TOKEN = "<YOUR_TOKEN_HERE>" | |
const bookmark = "YOUR_BOOKMARK" | |
const channelID = "YOUR_CHANNEL" | |
func main() { | |
api := slack.New(TOKEN) | |
smile := ":smile:" | |
empty := "" | |
testEmoji(api, &smile) | |
testEmoji(api, nil) | |
testEmoji(api, &empty) | |
} | |
func testEmoji(api *slack.Client, emoji *string) { | |
fmt.Printf("Emoji: %#v\n", emoji) | |
if emoji != nil { | |
fmt.Printf("%#v\n", *emoji) | |
} | |
params := slack.EditBookmarkParameters{ | |
Emoji: emoji, | |
} | |
bk, err := api.EditBookmark(channelID, bookmark, params) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println(prettyStruct(bk)) | |
} | |
func prettyStruct(data interface{}) string { | |
val, err := json.MarshalIndent(data, "", " ") | |
if err != nil { | |
panic(err) | |
} | |
return string(val) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
slack % go run github.com/slack-go/slack/cmd | |
Emoji: (*string)(0x14000112d80) | |
":smile:" | |
{ | |
"id": "Bk037M7FKNKZ", | |
"channel_id": "C038EDJ6HDX", | |
"title": "example", | |
"link": "https://example.com", | |
"emoji": ":smile:", | |
"icon_url": "", | |
"type": "link", | |
"date_created": 1647925554, | |
"date_updated": 1647928061, | |
"rank": "U", | |
"last_updated_by_user_id": "U0381QYN0KC", | |
"last_updated_by_team_id": "T6H5AR4QY", | |
"shortcut_id": "", | |
"entity_id": "", | |
"app_id": "" | |
} | |
Emoji: (*string)(nil) | |
{ | |
"id": "Bk037M7FKNKZ", | |
"channel_id": "C038EDJ6HDX", | |
"title": "example", | |
"link": "https://example.com", | |
"emoji": ":smile:", | |
"icon_url": "", | |
"type": "link", | |
"date_created": 1647925554, | |
"date_updated": 1647928061, | |
"rank": "U", | |
"last_updated_by_user_id": "U0381QYN0KC", | |
"last_updated_by_team_id": "T6H5AR4QY", | |
"shortcut_id": "", | |
"entity_id": "", | |
"app_id": "" | |
} | |
Emoji: (*string)(0x14000112d90) | |
"" | |
{ | |
"id": "Bk037M7FKNKZ", | |
"channel_id": "C038EDJ6HDX", | |
"title": "example", | |
"link": "https://example.com", | |
"emoji": "", | |
"icon_url": "", | |
"type": "link", | |
"date_created": 1647925554, | |
"date_updated": 1647928062, | |
"rank": "U", | |
"last_updated_by_user_id": "U0381QYN0KC", | |
"last_updated_by_team_id": "T6H5AR4QY", | |
"shortcut_id": "", | |
"entity_id": "", | |
"app_id": "" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment