MCPcopy
hub / github.com/gopherdata/gophernotes / fillDefaults

Function fillDefaults

display.go:290–318  ·  view source on GitHub ↗
(data Data, arg interface{}, s string, b []byte, mimeType string, err error)

Source from the content-addressed store, hash-verified

288}
289
290func fillDefaults(data Data, arg interface{}, s string, b []byte, mimeType string, err error) Data {
291 if err != nil {
292 return makeDataErr(err)
293 }
294 if data.Data == nil {
295 data.Data = make(MIMEMap)
296 }
297 // cannot autodetect the mime type of a string
298 if len(s) != 0 && len(mimeType) != 0 {
299 data.Data[mimeType] = s
300 }
301 // ensure plain text is set
302 if data.Data[MIMETypeText] == "" {
303 if len(s) == 0 {
304 s = fmt.Sprint(arg)
305 }
306 data.Data[MIMETypeText] = s
307 }
308 // if []byte is available, use it
309 if len(b) != 0 {
310 if len(mimeType) == 0 {
311 mimeType = http.DetectContentType(b)
312 }
313 if len(mimeType) != 0 && mimeType != MIMETypeText {
314 data.Data[mimeType] = b
315 }
316 }
317 return data
318}
319
320// do our best to render data graphically
321func render(mimeType string, data interface{}) Data {

Callers 2

autoRenderMethod · 0.85
renderFunction · 0.85

Calls 1

makeDataErrFunction · 0.85

Tested by

no test coverage detected