Skip to content

Commit

Permalink
Merge pull request #12 from kpandya3/kpandya/fix-string-arr-return
Browse files Browse the repository at this point in the history
Add a type to handle string or string arr returns
  • Loading branch information
rafaelsideguide authored Dec 16, 2024
2 parents ebbcb37 + 599d4e3 commit c464988
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 36 deletions.
82 changes: 50 additions & 32 deletions firecrawl.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,58 @@ import (
"time"
)

type StringOrStringSlice []string

func (s *StringOrStringSlice) UnmarshalJSON(data []byte) error {
var single string
if err := json.Unmarshal(data, &single); err == nil {
*s = []string{single}
return nil
}

var list []string
if err := json.Unmarshal(data, &list); err == nil {
*s = list
return nil
}

return fmt.Errorf("field is neither a string nor a list of strings")
}

// FirecrawlDocumentMetadata represents metadata for a Firecrawl document
type FirecrawlDocumentMetadata struct {
Title *string `json:"title,omitempty"`
Description *string `json:"description,omitempty"`
Language *string `json:"language,omitempty"`
Keywords *string `json:"keywords,omitempty"`
Robots *string `json:"robots,omitempty"`
OGTitle *string `json:"ogTitle,omitempty"`
OGDescription *string `json:"ogDescription,omitempty"`
OGURL *string `json:"ogUrl,omitempty"`
OGImage *string `json:"ogImage,omitempty"`
OGAudio *string `json:"ogAudio,omitempty"`
OGDeterminer *string `json:"ogDeterminer,omitempty"`
OGLocale *string `json:"ogLocale,omitempty"`
OGLocaleAlternate []*string `json:"ogLocaleAlternate,omitempty"`
OGSiteName *string `json:"ogSiteName,omitempty"`
OGVideo *string `json:"ogVideo,omitempty"`
DCTermsCreated *string `json:"dctermsCreated,omitempty"`
DCDateCreated *string `json:"dcDateCreated,omitempty"`
DCDate *string `json:"dcDate,omitempty"`
DCTermsType *string `json:"dctermsType,omitempty"`
DCType *string `json:"dcType,omitempty"`
DCTermsAudience *string `json:"dctermsAudience,omitempty"`
DCTermsSubject *string `json:"dctermsSubject,omitempty"`
DCSubject *string `json:"dcSubject,omitempty"`
DCDescription *string `json:"dcDescription,omitempty"`
DCTermsKeywords *string `json:"dctermsKeywords,omitempty"`
ModifiedTime *string `json:"modifiedTime,omitempty"`
PublishedTime *string `json:"publishedTime,omitempty"`
ArticleTag *string `json:"articleTag,omitempty"`
ArticleSection *string `json:"articleSection,omitempty"`
SourceURL *string `json:"sourceURL,omitempty"`
StatusCode *int `json:"statusCode,omitempty"`
Error *string `json:"error,omitempty"`
Title *string `json:"title,omitempty"`
Description *StringOrStringSlice `json:"description,omitempty"`
Language *string `json:"language,omitempty"`
Keywords *StringOrStringSlice `json:"keywords,omitempty"`
Robots *StringOrStringSlice `json:"robots,omitempty"`
OGTitle *string `json:"ogTitle,omitempty"`
OGDescription *string `json:"ogDescription,omitempty"`
OGURL *string `json:"ogUrl,omitempty"`
OGImage *string `json:"ogImage,omitempty"`
OGAudio *string `json:"ogAudio,omitempty"`
OGDeterminer *string `json:"ogDeterminer,omitempty"`
OGLocale *string `json:"ogLocale,omitempty"`
OGLocaleAlternate []*string `json:"ogLocaleAlternate,omitempty"`
OGSiteName *string `json:"ogSiteName,omitempty"`
OGVideo *string `json:"ogVideo,omitempty"`
DCTermsCreated *string `json:"dctermsCreated,omitempty"`
DCDateCreated *string `json:"dcDateCreated,omitempty"`
DCDate *string `json:"dcDate,omitempty"`
DCTermsType *string `json:"dctermsType,omitempty"`
DCType *string `json:"dcType,omitempty"`
DCTermsAudience *string `json:"dctermsAudience,omitempty"`
DCTermsSubject *string `json:"dctermsSubject,omitempty"`
DCSubject *string `json:"dcSubject,omitempty"`
DCDescription *string `json:"dcDescription,omitempty"`
DCTermsKeywords *string `json:"dctermsKeywords,omitempty"`
ModifiedTime *string `json:"modifiedTime,omitempty"`
PublishedTime *string `json:"publishedTime,omitempty"`
ArticleTag *string `json:"articleTag,omitempty"`
ArticleSection *string `json:"articleSection,omitempty"`
SourceURL *string `json:"sourceURL,omitempty"`
StatusCode *int `json:"statusCode,omitempty"`
Error *string `json:"error,omitempty"`
}

// FirecrawlDocument represents a document in Firecrawl
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module github.com/mendableai/firecrawl-go
module github.com/mendableai/firecrawl-go/v2

go 1.22.5

require (
github.com/google/uuid v1.6.0
github.com/joho/godotenv v1.5.1
github.com/stretchr/testify v1.9.0
github.com/stretchr/testify v1.10.0
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down

0 comments on commit c464988

Please sign in to comment.