Documentation
¶
Index ¶
- Constants
- Variables
- func AllTags(ctx context.Context) ([]string, error)
- func GeoConvertValue(v interface{}) (driver.Value, error)
- func GeoScanner(g interface{}) *wkb.GeometryScanner
- func GetMaxID(ctx context.Context) (int64, error)
- func InitDB(dataSourceName string) (*sql.DB, error)
- func Markdown(str string) template.HTML
- func NewExecutableSchema(cfg Config) graphql.ExecutableSchema
- func ParseLimit(lim *Limit, defaultLimit, defaultOffset int) (int, int)
- func ParseTags(text string) ([]string, error)
- func SummarizeText(str string) string
- func WithUser(ctx context.Context, u *User) context.Context
- type AddComment
- type Book
- type Cache
- type Comment
- type ComplexityRoot
- type Config
- type DirectiveRoot
- type Duration
- type EditBook
- type EditPost
- type Geo
- type InputGeo
- type Limit
- type Link
- type Linkable
- type Log
- type MutationResolver
- type NewLink
- type NewLog
- type NewStat
- type NewTweet
- type Photo
- type Post
- func Drafts(ctx context.Context, limit, offset int) ([]*Post, error)
- func FuturePosts(ctx context.Context, limit int, offset int) ([]*Post, error)
- func GetPost(ctx context.Context, id int64) (*Post, error)
- func GetPostString(ctx context.Context, id string) (*Post, error)
- func GetRandomPosts(ctx context.Context, limit int, notIn []int64) ([]*Post, error)
- func Posts(ctx context.Context, limit int, offset int) ([]*Post, error)
- func PostsByTag(ctx context.Context, tag string) ([]*Post, error)
- func Search(ctx context.Context, searchQuery string, limit int, offset int) ([]*Post, error)
- func (p *Post) Comments(ctx context.Context, input *Limit) ([]*Comment, error)
- func (p *Post) GetURI() URI
- func (p *Post) HTML() template.HTML
- func (p *Post) IntID() int64
- func (p *Post) IsLinkable()
- func (p *Post) Next(ctx context.Context) (*Post, error)
- func (p *Post) Prev(ctx context.Context) (*Post, error)
- func (p *Post) Readtime(_ context.Context) int32
- func (p *Post) Related(ctx context.Context, input *Limit) ([]*Post, error)
- func (p *Post) Save(ctx context.Context) error
- func (p *Post) SocialImage(ctx context.Context) (*URI, error)
- func (p *Post) Summary() string
- func (p *Post) URI() *URI
- type QueryResolver
- type Resolver
- type ResolverRoot
- type Role
- type Searchable
- type Sector
- type Stat
- type Tweet
- type TwitterURL
- type URI
- type User
Constants ¶
const (
// AppName is the name of the service in GCP.
AppName = "graphql"
)
const (
// StorageBucketName is the bucket name we are uploading to.
StorageBucketName = "icco-cloud"
)
Variables ¶
var ( // HashtagRegex is a regex for finding hashtags in Markdown. HashtagRegex = regexp.MustCompile(`(\s)#(\w+)`) // TwitterHandleRegex is a regex for finding @username in Markdown. TwitterHandleRegex = regexp.MustCompile(`(\s)@([_A-Za-z0-9]+)`) )
var AllRole = []Role{ RoleAdmin, RoleNormal, }
var AllSector = []Sector{ SectorCode, SectorWriting, SectorAudio, SectorResearch, SectorSocial, SectorPersonal, }
Functions ¶
func GeoConvertValue ¶
GeoConvertValue is used for marshaling data to a database.
func GeoScanner ¶
func GeoScanner(g interface{}) *wkb.GeometryScanner
GeoScanner is used for unmarshaling data from a database row.
func NewExecutableSchema ¶
func NewExecutableSchema(cfg Config) graphql.ExecutableSchema
NewExecutableSchema creates an ExecutableSchema from the ResolverRoot interface.
func ParseLimit ¶
ParseLimit turns a limit and applies defaults into a pair of ints.
func SummarizeText ¶
SummarizeText takes a chunk of markdown and just returns the first paragraph.
Types ¶
type AddComment ¶
type Book ¶
type Book struct {
ID string `json:"id"`
GoodreadsID string
Title string `json:"title"`
Link string
Authors []string
ISBN string
Created time.Time `json:"created"`
Modified time.Time `json:"modified"`
}
Book is a book on Goodreads.
func (Book) IsLinkable ¶
func (Book) IsLinkable()
IsLinkable exists to show that this method implements the Linkable type in graphql.
type Cache ¶
type Cache struct {
}
Cache is a basic type as defined by gqlgen.
type Comment ¶
type Comment struct {
ID string `json:"id"`
Post *Post `json:"post"`
User *User `json:"author"`
Content string `json:"content"`
Created time.Time `json:"created"`
Modified time.Time `json:"modified"`
}
Comment is a comment on a post.
func AllComments ¶
AllComments returns all comments orderd by time.
func GetComment ¶
GetComment returns a single comment by ID.
func PostComments ¶
PostComments returns comments for a post ID.
func (Comment) IsLinkable ¶
func (Comment) IsLinkable()
IsLinkable tells gqlgen this model has a URI function.
type ComplexityRoot ¶
type ComplexityRoot struct {
Book struct {
ID func(childComplexity int) int
Title func(childComplexity int) int
URI func(childComplexity int) int
}
Comment struct {
Content func(childComplexity int) int
Created func(childComplexity int) int
ID func(childComplexity int) int
Modified func(childComplexity int) int
Post func(childComplexity int) int
URI func(childComplexity int) int
User func(childComplexity int) int
}
Geo struct {
Lat func(childComplexity int) int
Long func(childComplexity int) int
}
Link struct {
Created func(childComplexity int) int
Description func(childComplexity int) int
ID func(childComplexity int) int
Modified func(childComplexity int) int
Screenshot func(childComplexity int) int
Tags func(childComplexity int) int
Title func(childComplexity int) int
URI func(childComplexity int) int
}
Log struct {
Created func(childComplexity int) int
Description func(childComplexity int) int
Duration func(childComplexity int) int
ID func(childComplexity int) int
Modified func(childComplexity int) int
Project func(childComplexity int) int
Sector func(childComplexity int) int
Started func(childComplexity int) int
Stopped func(childComplexity int) int
URI func(childComplexity int) int
User func(childComplexity int) int
}
Mutation struct {
AddComment func(childComplexity int, input AddComment) int
CreatePost func(childComplexity int, input EditPost) int
EditPost func(childComplexity int, input EditPost) int
InsertLog func(childComplexity int, input NewLog) int
UpsertBook func(childComplexity int, input EditBook) int
UpsertLink func(childComplexity int, input NewLink) int
UpsertStat func(childComplexity int, input NewStat) int
UpsertTweet func(childComplexity int, input NewTweet) int
}
Photo struct {
ContentType func(childComplexity int) int
Created func(childComplexity int) int
ID func(childComplexity int) int
Modified func(childComplexity int) int
URI func(childComplexity int) int
Year func(childComplexity int) int
}
Post struct {
Comments func(childComplexity int, input *Limit) int
Content func(childComplexity int) int
Created func(childComplexity int) int
Datetime func(childComplexity int) int
Draft func(childComplexity int) int
ID func(childComplexity int) int
Links func(childComplexity int) int
Modified func(childComplexity int) int
Next func(childComplexity int) int
Prev func(childComplexity int) int
Readtime func(childComplexity int) int
Related func(childComplexity int, input *Limit) int
SocialImage func(childComplexity int) int
Summary func(childComplexity int) int
Tags func(childComplexity int) int
Title func(childComplexity int) int
URI func(childComplexity int) int
}
Query struct {
Books func(childComplexity int, input *Limit) int
Comments func(childComplexity int, input *Limit) int
Counts func(childComplexity int) int
Drafts func(childComplexity int, input *Limit) int
FuturePosts func(childComplexity int, input *Limit) int
HomeTimelineURLs func(childComplexity int, input *Limit) int
Link func(childComplexity int, id *string, url *URI) int
Links func(childComplexity int, input *Limit) int
Log func(childComplexity int, id string) int
Logs func(childComplexity int, input *Limit) int
NextPost func(childComplexity int, id string) int
Photos func(childComplexity int, input *Limit) int
Post func(childComplexity int, id string) int
Posts func(childComplexity int, input *Limit) int
PostsByTag func(childComplexity int, id string) int
PrevPost func(childComplexity int, id string) int
Search func(childComplexity int, query string, input *Limit) int
Stat func(childComplexity int, key string, input *Limit) int
Stats func(childComplexity int, count *int) int
Tags func(childComplexity int) int
Time func(childComplexity int) int
Tweet func(childComplexity int, id string) int
Tweets func(childComplexity int, input *Limit) int
TweetsByScreenName func(childComplexity int, screenName string, input *Limit) int
Whoami func(childComplexity int) int
}
Stat struct {
Key func(childComplexity int) int
Value func(childComplexity int) int
When func(childComplexity int) int
}
Tweet struct {
FavoriteCount func(childComplexity int) int
Hashtags func(childComplexity int) int
ID func(childComplexity int) int
Posted func(childComplexity int) int
RetweetCount func(childComplexity int) int
ScreenName func(childComplexity int) int
Symbols func(childComplexity int) int
Text func(childComplexity int) int
URI func(childComplexity int) int
Urls func(childComplexity int) int
UserMentions func(childComplexity int) int
}
TwitterURL struct {
CreatedAt func(childComplexity int) int
Link func(childComplexity int) int
ModifiedAt func(childComplexity int) int
TweetIDs func(childComplexity int) int
Tweets func(childComplexity int) int
URI func(childComplexity int) int
}
User struct {
APIKey func(childComplexity int) int
Created func(childComplexity int) int
ID func(childComplexity int) int
Modified func(childComplexity int) int
Name func(childComplexity int) int
Role func(childComplexity int) int
}
}
type Config ¶
type Config struct {
Schema *ast.Schema
Resolvers ResolverRoot
Directives DirectiveRoot
Complexity ComplexityRoot
}
type DirectiveRoot ¶
type Duration ¶
type Duration struct {
// contains filtered or unexported fields
}
Duration is a float64 representation of a Duration in seconds.
func ParseDurationFromDuration ¶
ParseDurationFromDuration takes a stdlib Duration and turns it into our duration.
func ParseDurationFromString ¶
ParseDurationFromString takes a duration string and turns it into a duration. A duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
func (Duration) MarshalGQL ¶
MarshalGQL implements the graphql.Marshaler interface.
func (Duration) MarshalJSON ¶
MarshalJSON turns a duration to a string.
func (*Duration) UnmarshalGQL ¶
UnmarshalGQL implements the graphql.Marshaler interface
func (*Duration) UnmarshalJSON ¶
UnmarshalJSON turns a string to a Duration.
type Geo ¶
Geo is a simple type for wrapping a point. Units are in Degrees.
func GeoFromOrb ¶
GeoFromOrb creates a Geo from github.com/paulmach/orb.Point.
type Link ¶
type Link struct {
ID string `json:"id"`
Title string `json:"title"`
URI URI `json:"uri"`
Created time.Time `json:"created"`
Description string `json:"description"`
Screenshot URI `json:"screenshot"`
Tags []string `json:"tags"`
Modified time.Time `json:"modified"`
}
Link is a link I have save on pinboard or a link in a post.
func GetLinkByID ¶
GetLinkByID gets a link by id from the database.
func GetLinkByURI ¶
GetLinkByURI gets a link by uri from the database.
func (*Link) IsLinkable ¶
func (l *Link) IsLinkable()
IsLinkable exists to show that this method implements the Linkable type in graphql.
type Log ¶
type Log struct {
ID string `json:"id"`
Sector Sector `json:"sector"`
Description string `json:"description"`
Project string `json:"project"`
User User `json:"user"`
Started time.Time `json:"started"`
Stopped time.Time `json:"stopped"`
Created time.Time `json:"created"`
Modified time.Time `json:"modified"`
}
A Log is a journal entry by an individual.
func (*Log) IsLinkable ¶
func (l *Log) IsLinkable()
IsLinkable exists to show that this method implements the Linkable type in graphql.
type MutationResolver ¶
type MutationResolver interface {
UpsertBook(ctx context.Context, input EditBook) (*Book, error)
UpsertLink(ctx context.Context, input NewLink) (*Link, error)
UpsertStat(ctx context.Context, input NewStat) (*Stat, error)
UpsertTweet(ctx context.Context, input NewTweet) (*Tweet, error)
AddComment(ctx context.Context, input AddComment) (*Comment, error)
CreatePost(ctx context.Context, input EditPost) (*Post, error)
EditPost(ctx context.Context, input EditPost) (*Post, error)
InsertLog(ctx context.Context, input NewLog) (*Log, error)
}
type NewTweet ¶
type NewTweet struct {
FavoriteCount int `json:"favorite_count"`
ID string `json:"id"`
Posted time.Time `json:"posted"`
RetweetCount int `json:"retweet_count"`
Symbols []string `json:"symbols,omitempty"`
Text string `json:"text"`
Urls []*URI `json:"urls,omitempty"`
ScreenName string `json:"screen_name"`
UserMentions []string `json:"user_mentions,omitempty"`
}
type Photo ¶
type Photo struct {
ID string `json:"id"`
User User `json:"user"`
Year int
ContentType string
Created time.Time `json:"created"`
Modified time.Time `json:"modified"`
}
Photo represents an uploaded photo
func UserPhotos ¶
UserPhotos gets all photos for a User.
func (*Photo) IsLinkable ¶
func (p *Photo) IsLinkable()
IsLinkable exists to show that this method implements the Linkable type in graphql.
type Post ¶
type Post struct {
ID string `json:"id"`
Title string `json:"title"`
Content string `json:"content"`
Datetime time.Time `json:"datetime"`
Created time.Time `json:"created"`
Modified time.Time `json:"modified"`
Draft bool `json:"draft"`
Tags []string `json:"tags"`
Links []*Link `json:"links"`
}
Post is our representation of a post in the database.
func FuturePosts ¶
FuturePosts returns some posts that are in the future.
func GetPostString ¶
GetPostString gets a post by an ID string.
func GetRandomPosts ¶
GetRandomPosts returns a random selection of posts.
func PostsByTag ¶
PostsByTag returns all posts with a tag.
func (*Post) IsLinkable ¶
func (p *Post) IsLinkable()
IsLinkable exists to show that this method implements the Linkable type in graphql.
func (*Post) Related ¶
Related returns an array of related posts. It is quite slow in comparison to other queries.
type QueryResolver ¶
type QueryResolver interface {
Books(ctx context.Context, input *Limit) ([]*Book, error)
Links(ctx context.Context, input *Limit) ([]*Link, error)
Link(ctx context.Context, id *string, url *URI) (*Link, error)
Stats(ctx context.Context, count *int) ([]*Stat, error)
Stat(ctx context.Context, key string, input *Limit) ([]*Stat, error)
Counts(ctx context.Context) ([]*Stat, error)
Whoami(ctx context.Context) (*User, error)
Tweets(ctx context.Context, input *Limit) ([]*Tweet, error)
Tweet(ctx context.Context, id string) (*Tweet, error)
TweetsByScreenName(ctx context.Context, screenName string, input *Limit) ([]*Tweet, error)
HomeTimelineURLs(ctx context.Context, input *Limit) ([]*TwitterURL, error)
Time(ctx context.Context) (*time.Time, error)
Drafts(ctx context.Context, input *Limit) ([]*Post, error)
FuturePosts(ctx context.Context, input *Limit) ([]*Post, error)
Posts(ctx context.Context, input *Limit) ([]*Post, error)
Comments(ctx context.Context, input *Limit) ([]*Comment, error)
Search(ctx context.Context, query string, input *Limit) ([]*Post, error)
Post(ctx context.Context, id string) (*Post, error)
NextPost(ctx context.Context, id string) (*Post, error)
PrevPost(ctx context.Context, id string) (*Post, error)
PostsByTag(ctx context.Context, id string) ([]*Post, error)
Tags(ctx context.Context) ([]string, error)
Logs(ctx context.Context, input *Limit) ([]*Log, error)
Log(ctx context.Context, id string) (*Log, error)
Photos(ctx context.Context, input *Limit) ([]*Photo, error)
}
type Resolver ¶
type Resolver struct{}
Resolver is the type that gqlgen expects to exist
func (*Resolver) Mutation ¶
func (r *Resolver) Mutation() MutationResolver
Mutation returns MutationResolver implementation.
func (*Resolver) Query ¶
func (r *Resolver) Query() QueryResolver
Query returns QueryResolver implementation.
type ResolverRoot ¶
type ResolverRoot interface {
Mutation() MutationResolver
Query() QueryResolver
}
type Searchable ¶
type Searchable interface {
IsSearchable()
GetSummary() string
}
type Stat ¶
type Stat struct {
Key string `json:"key"`
Value float64 `json:"value"`
When time.Time `json:"when"`
}
A stat is a key value pair of two interesting strings.
type Tweet ¶
type Tweet struct {
ID string `json:"id"`
Text string `json:"text"`
Symbols []string `json:"symbols"`
UserMentions []string `json:"user_mentions"`
Urls []*URI `json:"urls"`
ScreenName string `json:"screen_name"`
FavoriteCount int `json:"favorite_count"`
RetweetCount int `json:"retweet_count"`
Posted time.Time `json:"posted"`
}
A Tweet is an archived tweet.
func GetTweetsByScreenName ¶
func GetTweetsByScreenName(ctx context.Context, screenName string, limit, offset int) ([]*Tweet, error)
GetTweetsByScreenName returns an array of tweets from the database filtered by screenname.
func (*Tweet) IsLinkable ¶
func (t *Tweet) IsLinkable()
IsLinkable exists to show that this method implements the Linkable type in graphql.
type TwitterURL ¶
TwitterURL is a representation of data from cacophony.
func (*TwitterURL) GetURI ¶
func (tu *TwitterURL) GetURI() URI
func (*TwitterURL) IsLinkable ¶
func (tu *TwitterURL) IsLinkable()
IsLinkable exists to show that this method implements the Linkable type in graphql.
type URI ¶
type URI struct {
// contains filtered or unexported fields
}
URI is a string representation of a URI. TODO: Turn into an actual URI.
func GenerateSocialImage ¶
GenerateSocialImage creates a static image URL for a post.
func (URI) MarshalGQL ¶
MarshalGQL implements the graphql.Marshaler interface
func (URI) MarshalJSON ¶
MarshalJSON implements the encoding/json interface.
func (*URI) UnmarshalGQL ¶
UnmarshalGQL implements the graphql.Marshaler interface
func (*URI) UnmarshalJSON ¶
UnmarshalJSON implements the encoding/json interface.
type User ¶
type User struct {
ID string
Name string
Role string
APIKey string
Created time.Time
Modified time.Time
}
User is a database object based off of what we get back from Google OAuth.
func GetUserByAPIKey ¶
GetUserByAPIKey returns a user from the database.
func GetUserFromContext ¶
GetUserFromContext finds the user from the context. This is usually inserted by WithUser.