Skip to content

Commit

Permalink
構造体の定義を types.go へ移動
Browse files Browse the repository at this point in the history
  • Loading branch information
rmatsuoka committed Aug 2, 2023
1 parent b58788d commit 97178a7
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 84 deletions.
84 changes: 0 additions & 84 deletions functions/saba_disambiguator/twitter/recent.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,90 +5,6 @@ import (
"net/http"
"net/url"
"strings"
"time"
)

type Tweet struct {
ID string
Text string
CreatedAt time.Time
User *User
Lang string
QuotedStatus *Tweet
InReplyToUserName string
Entities []Entities
}

type User struct {
ID string `json:"id"`
Name string `json:"name"`
UserName string `json:"username"`
Description string `json:"description"`
ProfileImageURL string `json:"profile_image_url"`
}

type Entities struct {
// 使われてない
// Annotations []any `json:"annotations"`
// 使われていない
// Cashtags []any `json:"cashtags"`

Hashtags []EntitiesHashTag `json:"hashtags"`
Mentions []EntitiesMention `json:"mentions"`
URLs []EntitiesURL `json:"urls"`
}

type EntitiesHashTag struct {
Start int `json:"start"`
End int `json:"end"`
Tag string `json:"tag"`
}

type EntitiesMention struct {
Start int `json:"start"`
End int `json:"end"`
UserName string `json:"username"`
}

type EntitiesURL struct {
Start int `json:"start"`
End int `json:"end"`
URL string `json:"url"`
ExpandedURL string `json:"expaneded_url"`
DisplayURL string `json:"display_url"`
UnwoundURL string `json:"unwound_url"`
}

type responseRecentSearch struct {
Data []responseTweet `json:"data"`
Includes struct {
Users []*User `json:"users"`
Tweets []*responseTweet `json:"tweets"`
} `json:"includes"`
}

type responseTweet struct {
ID string `json:"id"`
Text string `json:"text"`
CreatedAt time.Time `json:"created_at"`
AuthorID string `json:"author_id"`
Lang string `json:"lang"`
Entities Entities `json:"entites"`
ReferencedTweets []referencedTweet `json:"referenced_tweets"`
InReplyToUserID string `json:"in_reply_to_user_id"`
}

type referencedTweet struct {
Type referencedTweetType `json:"type"`
ID string `json:"id"`
}

type referencedTweetType string

const (
typeRetweeted referencedTweetType = "retweeted"
typeQuoted referencedTweetType = "quoted"
typeRepliedTo referencedTweetType = "replied_to"
)

type BearerToken string
Expand Down
86 changes: 86 additions & 0 deletions functions/saba_disambiguator/twitter/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package twitter2

import "time"

type Tweet struct {
ID string
Text string
CreatedAt time.Time
User *User
Lang string
QuotedStatus *Tweet
InReplyToUserName string
Entities []Entities
}

type User struct {
ID string `json:"id"`
Name string `json:"name"`
UserName string `json:"username"`
Description string `json:"description"`
ProfileImageURL string `json:"profile_image_url"`
}

type Entities struct {
// 使われてない
// Annotations []any `json:"annotations"`
// 使われていない
// Cashtags []any `json:"cashtags"`

Hashtags []EntitiesHashTag `json:"hashtags"`
Mentions []EntitiesMention `json:"mentions"`
URLs []EntitiesURL `json:"urls"`
}

type EntitiesHashTag struct {
Start int `json:"start"`
End int `json:"end"`
Tag string `json:"tag"`
}

type EntitiesMention struct {
Start int `json:"start"`
End int `json:"end"`
UserName string `json:"username"`
}

type EntitiesURL struct {
Start int `json:"start"`
End int `json:"end"`
URL string `json:"url"`
ExpandedURL string `json:"expaneded_url"`
DisplayURL string `json:"display_url"`
UnwoundURL string `json:"unwound_url"`
}

type responseRecentSearch struct {
Data []responseTweet `json:"data"`
Includes struct {
Users []*User `json:"users"`
Tweets []*responseTweet `json:"tweets"`
} `json:"includes"`
}

type responseTweet struct {
ID string `json:"id"`
Text string `json:"text"`
CreatedAt time.Time `json:"created_at"`
AuthorID string `json:"author_id"`
Lang string `json:"lang"`
Entities Entities `json:"entites"`
ReferencedTweets []referencedTweet `json:"referenced_tweets"`
InReplyToUserID string `json:"in_reply_to_user_id"`
}

type referencedTweet struct {
Type referencedTweetType `json:"type"`
ID string `json:"id"`
}

type referencedTweetType string

const (
typeRetweeted referencedTweetType = "retweeted"
typeQuoted referencedTweetType = "quoted"
typeRepliedTo referencedTweetType = "replied_to"
)

0 comments on commit 97178a7

Please sign in to comment.