readinglist

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2019 License: Apache-2.0 Imports: 23 Imported by: 0

README

The 'Reading List' Example

This example implements a clone of NYT's 'saved articles API' that allows users to save, delete and retrieve nytimes.com article URLs.

Instead of utilizing NYT's auth, this example leans on Google OAuth for user identity. When running locally, GAE's dev_appserver.py appears to always inject a user with an ID of "0".

To run this service, you must be using Google Cloud SDK >= 162.0.0 or the "original" App Engine Go SDK >= 1.9.56. Then execute the following command:

# If using Cloud SDK:
dev_appserver.py server/app.yaml
# If using the original SDK:
goapp serve server/app.yaml

At that point the application should be served on http://localhost:8080.

A few highlights of this service worth calling out:

  • service.yaml
    • An Open API specification that describes the endpoints and how they support JSON or Protobufs.
  • gen-proto.sh
    • A script that relies on github.com/NYTimes/openapi2proto to generate Protobuf IDL from the Open API spec along with the Protobuf stubs via protoc.
  • service.go
  • client.go
    • A go-kit client for programmatically accessing the API.
  • cmd/cli/main.go
    • A CLI wrapper around the go-kit client.
  • Gopkg.toml
    • To have truly reproducible builds across environments in the GAE Standard environment, this example uses the dep command to ensure all dependencies.
  • server/app.yaml
    • The app config is in a nested directory to enable vendoring.
    • This structure (along with using the legacy SDK) is the only way we've been able to get it to work with the current SDKs available.
  • .drone.yaml
    • An example configuration file for Drone CI using the NYTimes/drone-gae plugin for managing automated deployments to App Engine.

This live demo is currently running on https://nyt-reading-list.appspot.com.

Documentation

Overview

Package readinglist is a generated protocol buffer package.

It is generated from these files:

service.proto

It has these top-level messages:

PutLinkProtoJSONRequest
GetListProtoJSONRequest
Link
LinkRequest
Links
Message

Index

Constants

View Source
const LinkKind = "Link"

Variables

This section is empty.

Functions

func NewService

func NewService(db DB) marvin.MixedService

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(host string, l log.Logger, opts ...httptransport.ClientOption) *Client
func (c Client) GetLinks(ctx context.Context, limit int) (*Links, error)
func (c Client) PutLink(ctx context.Context, url string, delete bool) (*Message, error)

type DB

type DB interface {
	GetLinks(ctx context.Context, userID string, limit int) ([]string, error)
	PutLink(ctx context.Context, userID string, url string) error
	DeleteLink(ctx context.Context, userID string, url string) error
}

type Datastore

type Datastore struct{}

func NewDB

func NewDB() Datastore
func (d Datastore) DeleteLink(ctx context.Context, userID string, url string) error
func (d Datastore) GetLinks(ctx context.Context, userID string, limit int) ([]string, error)
func (d Datastore) PutLink(ctx context.Context, userID string, url string) error

type GetListProtoJSONRequest

type GetListProtoJSONRequest struct {
	// The limit of links to fetch
	Limit int32 `protobuf:"varint,2,opt,name=limit" json:"limit,omitempty"`
	// The transport to respond with (Protobuf or JSON).
	ProtoJSON string `protobuf:"bytes,1,opt,name=protoJSON" json:"protoJSON,omitempty"`
}

func (*GetListProtoJSONRequest) Descriptor

func (*GetListProtoJSONRequest) Descriptor() ([]byte, []int)

func (*GetListProtoJSONRequest) GetLimit

func (m *GetListProtoJSONRequest) GetLimit() int32

func (*GetListProtoJSONRequest) GetProtoJSON

func (m *GetListProtoJSONRequest) GetProtoJSON() string

func (*GetListProtoJSONRequest) ProtoMessage

func (*GetListProtoJSONRequest) ProtoMessage()

func (*GetListProtoJSONRequest) Reset

func (m *GetListProtoJSONRequest) Reset()

func (*GetListProtoJSONRequest) String

func (m *GetListProtoJSONRequest) String() string
type Link struct {
	Url string `protobuf:"bytes,1,opt,name=url" json:"url,omitempty"`
}

func (*Link) Descriptor

func (*Link) Descriptor() ([]byte, []int)

func (*Link) GetUrl

func (m *Link) GetUrl() string

func (*Link) ProtoMessage

func (*Link) ProtoMessage()

func (*Link) Reset

func (m *Link) Reset()

func (*Link) String

func (m *Link) String() string

type LinkRequest

type LinkRequest struct {
	// True to remove this link from the user's list.
	Delete bool  `protobuf:"varint,1,opt,name=delete" json:"delete,omitempty"`
	Link   *Link `protobuf:"bytes,2,opt,name=link" json:"link,omitempty"`
}

func (*LinkRequest) Descriptor

func (*LinkRequest) Descriptor() ([]byte, []int)

func (*LinkRequest) GetDelete

func (m *LinkRequest) GetDelete() bool
func (m *LinkRequest) GetLink() *Link

func (*LinkRequest) ProtoMessage

func (*LinkRequest) ProtoMessage()

func (*LinkRequest) Reset

func (m *LinkRequest) Reset()

func (*LinkRequest) String

func (m *LinkRequest) String() string
type Links struct {
	Links []*Link `protobuf:"bytes,1,rep,name=links" json:"links,omitempty"`
}

func (*Links) Descriptor

func (*Links) Descriptor() ([]byte, []int)
func (m *Links) GetLinks() []*Link

func (*Links) ProtoMessage

func (*Links) ProtoMessage()

func (*Links) Reset

func (m *Links) Reset()

func (*Links) String

func (m *Links) String() string

type Message

type Message struct {
	Message string `protobuf:"bytes,1,opt,name=message" json:"message,omitempty"`
}

func (*Message) Descriptor

func (*Message) Descriptor() ([]byte, []int)

func (*Message) GetMessage

func (m *Message) GetMessage() string

func (*Message) ProtoMessage

func (*Message) ProtoMessage()

func (*Message) Reset

func (m *Message) Reset()

func (*Message) String

func (m *Message) String() string

type PutLinkProtoJSONRequest

type PutLinkProtoJSONRequest struct {
	// The transport to respond with (Protobuf or JSON)
	ProtoJSON string `protobuf:"bytes,1,opt,name=protoJSON" json:"protoJSON,omitempty"`
	// The Link to save
	Request *LinkRequest `protobuf:"bytes,2,opt,name=request" json:"request,omitempty"`
}

func (*PutLinkProtoJSONRequest) Descriptor

func (*PutLinkProtoJSONRequest) Descriptor() ([]byte, []int)

func (*PutLinkProtoJSONRequest) GetProtoJSON

func (m *PutLinkProtoJSONRequest) GetProtoJSON() string

func (*PutLinkProtoJSONRequest) GetRequest

func (m *PutLinkProtoJSONRequest) GetRequest() *LinkRequest

func (*PutLinkProtoJSONRequest) ProtoMessage

func (*PutLinkProtoJSONRequest) ProtoMessage()

func (*PutLinkProtoJSONRequest) Reset

func (m *PutLinkProtoJSONRequest) Reset()

func (*PutLinkProtoJSONRequest) String

func (m *PutLinkProtoJSONRequest) String() string

Directories

Path Synopsis
cmd
cli

Jump to

Keyboard shortcuts

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