0
Fork 0
mirror of https://codeberg.org/SafeTwitch/safetwitch-backend.git synced 2024-12-22 13:13:00 -05:00
safetwitch-backend/extractor/parser.go
2023-05-22 07:29:15 -04:00

26 lines
628 B
Go

package extractor
import (
"errors"
"safetwitch-backend/extractor/structs"
"github.com/tidwall/gjson"
)
func ParseSocials(data string) ([]structs.Social, error) {
var parsedSocials []structs.Social
result := gjson.Get(data, "user.channel.socialMedias")
for _, social := range result.Array() {
parsedSocials = append(parsedSocials, structs.Social{
Title: social.Get("title").String(),
Type: social.Get("name").String(),
Url: social.Get("url").String(),
})
}
if !result.Exists() {
return parsedSocials, errors.New("Error while parsing socials, path does not exist.")
}
return parsedSocials, nil
}