MCPcopy Index your code
hub / github.com/Preloading/TwitterAPIBridge / EncodeAndSend

Function EncodeAndSend

twitterv1/twitterv1.go:167–197  ·  view source on GitHub ↗
(c *fiber.Ctx, data interface{})

Source from the content-addressed store, hash-verified

165}
166
167func EncodeAndSend(c *fiber.Ctx, data interface{}) error {
168 encodeType := c.Params("filetype")
169 switch encodeType {
170 case "xml":
171 // Encode the data to XML
172 var buf bytes.Buffer
173 enc := xml.NewEncoder(&buf)
174 enc.Indent("", " ")
175 if err := enc.Encode(data); err != nil {
176 fmt.Println("Error encoding XML:", err)
177 return c.Status(fiber.StatusInternalServerError).SendString("Failed to encode into XML!")
178 }
179
180 // Add custom XML header
181 xmlContent := buf.Bytes()
182 customHeader := []byte(`<?xml version="1.0" encoding="UTF-8"?>`)
183 xmlContent = append(customHeader, xmlContent...)
184
185 return c.SendString(string(xmlContent))
186 case "json":
187 encoded, err := json.Marshal(data)
188 if err != nil {
189 fmt.Println("Error:", err)
190 return c.Status(fiber.StatusInternalServerError).SendString("Failed to encode into json!")
191 }
192 return c.SendString(string(encoded))
193 default:
194 return c.Status(fiber.StatusInternalServerError).SendString("Invalid file type!")
195 }
196
197}

Callers 15

GetSettingsFunction · 0.85
UpdateProfileFunction · 0.85
UpdateProfilePictureFunction · 0.85
UserSearchFunction · 0.85
SearchAheadFunction · 0.85
GetMyActivityFunction · 0.85
VerifyCredentialsFunction · 0.85
GetUsersListsFunction · 0.85
GetListMembersFunction · 0.85
convert_timelineFunction · 0.85
RelatedResultsFunction · 0.85
GetStatusFromIdFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected