queries

package
v0.0.0-...-faaa73c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	GetPostDetail = `` /* 431-byte string literal not displayed */

	GetTimeline = `
	user(username: \"%s\") { 
		publication { 
			posts(page:%d) { 
				slug
				dateAdded
				dateUpdated
			} 
		} 
	}`
)
View Source
var (
	PostUnmarshaler = func(bytes []byte) (any, error) {
		var e PostError
		if err := json.Unmarshal(bytes, &e); err != nil {
			return nil, err
		}

		if len(e.Errors) > 0 {
			return nil, fmt.Errorf("unexpected API response: %s", e.Errors[0]["message"])
		}

		// { "data": { "post": { ... } } }
		var results map[string]map[string]*models.Post
		if err := json.Unmarshal(bytes, &results); err != nil {
			return nil, err
		}

		return results["data"]["post"], nil
	}

	TimelineUnmarshaler = func(bytes []byte) (any, error) {
		// { "data": { "user": { "publication": { "posts": [ ... ] } } } }
		var results map[string]map[string]map[string]map[string][]models.Post
		if err := json.Unmarshal(bytes, &results); err != nil {
			return nil, err
		}

		return results["data"]["user"]["publication"]["posts"], nil
	}
)

Functions

This section is empty.

Types

type PostError

type PostError struct {
	Errors []map[string]any
}

type Query

type Query struct {
	Name  string
	Query string

	Unmarshaler func([]byte) (any, error)
	Backoff     *backoff.Backoff
	// contains filtered or unexported fields
}

Query

func New

func New(name, query string, unmarshaler func([]byte) (any, error), args ...any) Query

New

func (*Query) String

func (q *Query) String() string

String

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL