go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/projects/nodes/pkg/types/svg.go (about) 1 /* 2 3 Copyright (c) 2023 - Present. Will Charczuk. All rights reserved. 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository. 5 6 */ 7 8 package types 9 10 import "fmt" 11 12 // SVGFromJSON returns an svg from a json object. 13 func SVGFromJSON(obj map[string]any) (*SVG, error) { 14 main, ok := obj["main"].(string) 15 if !ok { 16 return nil, fmt.Errorf("invalid json object for svg; missing 'main' field") 17 } 18 thumbnail, ok := obj["thumbnail"].(string) 19 if !ok { 20 return nil, fmt.Errorf("invalid json object for svg; missing 'thumbnail' field") 21 } 22 return &SVG{ 23 Main: main, 24 Thumbnail: thumbnail, 25 }, nil 26 } 27 28 // SVG is effectively a pair of very large strings. 29 type SVG struct { 30 Main string `json:"main"` 31 Thumbnail string `json:"thumbnail"` 32 }