Skip to content

Commit

Permalink
feat: replace all [null] with proper [] when marshaling json
Browse files Browse the repository at this point in the history
  • Loading branch information
amatsagu committed Dec 31, 2023
1 parent 6b243f0 commit f63573f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ var (
private_ACKNOWLEDGE_RESPONSE_RAW_BODY = []byte(fmt.Sprintf(`{"type":%d}`, DEFERRED_UPDATE_MESSAGE_RESPONSE_TYPE))
private_UNKNOWN_COMMAND_RESPONSE_RAW_BODY = []byte(fmt.Sprintf(`{"type":%d,"data":{"content":"Oh uh.. It looks like you tried to trigger (/) unknown command. Please report this bug to bot owner.","flags":64}}`, CHANNEL_MESSAGE_WITH_SOURCE_RESPONSE_TYPE))
)

// Those are used to replace seemingly empty slice into empty array after marsalling struct to json string.
var (
private_REST_NULL_SLICE_FIND []byte = []byte("[null]")
private_REST_NULL_SLICE_REPLACE []byte = []byte("[]")
)
4 changes: 2 additions & 2 deletions rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ func (rest *iRest) handleRequest(method string, route string, jsonPayload interf
request, err := http.NewRequest(
method,
DISCORD_API_URL+route,
bytes.ReplaceAll(
bytes.NewBuffer(bytes.ReplaceAll(
body,
private_REST_NULL_SLICE_FIND,
private_REST_NULL_SLICE_REPLACE,
),
)),
)

if err != nil {
Expand Down

0 comments on commit f63573f

Please sign in to comment.