service

package
v0.0.0-...-ed9fe1d Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2018 License: BSD-3-Clause Imports: 24 Imported by: 0

Documentation

Overview

Package service provides a gae service instance framework on top of github.com/speedland/go/web package.

Using this package, what you need to do in your GAE app looks like this:

// app.go

func init(){
    s := service.New("serviceKey")
    s.Get("/path/to/endpoint/", web.HandlerFunc(...))  // register /serviceKey/path/to/endpoint handler
    ...
    s.Run()
}

Index

Constants

This section is empty.

Variables

View Source
var ContextKey = xcontext.NewKey("service")

ContextKey is a key to get a service.

View Source
var CronTimezone = "Asia/Tokyo"

CronTimezone is a timezone used in cron.yaml

Functions

func NewHTTPClient

func NewHTTPClient(ctx context.Context) (c *http.Client)

NewHTTPClient returns *http.Client under the gae service context

func WithContext

func WithContext(ctx context.Context, s *Service) context.Context

WithContext returns a new context.Context associated with the service

Types

type BuiltInAPIConfig

type BuiltInAPIConfig struct {
	AuthNamespace    string
	MessengerWebHook messenger.Webhook
}

BuiltInAPIConfig is a configuration object for setupBuiltInAPIs

type Cron

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

func (*Cron) ToYAML

func (c *Cron) ToYAML() string

type Service

type Service struct {
	Init      func(*web.Request)
	Every     func(*web.Request)
	OnError   func(*web.Request, error) *response.Response
	Config    *config.Config // Configuration that admin can update.
	APIConfig *BuiltInAPIConfig
	// contains filtered or unexported fields
}

Service is a set of endpoints

func FromContext

func FromContext(ctx context.Context) *Service

FromContext returns a service object associated with the context

func MustFromContext

func MustFromContext(ctx context.Context) *Service

MustFromContext is like FromContext but panics if a service is not in the context

func New

func New(key string) *Service

New returns a new *Service instance

func NewWithURLAndNamespace

func NewWithURLAndNamespace(key string, url string, namespace string) *Service

NewWithURLAndNamespace is like New with using the given url prefix and namespece instead of 'key' value.

func (*Service) AddCron

func (s *Service) AddCron(path, time, desc string, handlers ...web.Handler)

func (*Service) AddPushQueue

func (s *Service) AddPushQueue(name string) *taskqueue.PushQueue

AddPushQueue adds a named queue into the service.

func (*Service) AsyncTask

func (s *Service) AsyncTask(path string, taskConfig *asynctask.Config)

AsyncTask defines endpoints for asynctask execution

func (*Service) Delete

func (s *Service) Delete(path string, handlers ...web.Handler)

Delete defines an endpoint for DELETE

func (*Service) GenCronYAML

func (s *Service) GenCronYAML(w io.Writer)

GenCronYAML generates cron yaml content to `w`

func (*Service) GenQueueYAML

func (s *Service) GenQueueYAML(w io.Writer)

GenQueueYAML generates cron yaml content to `w`

func (*Service) Get

func (s *Service) Get(path string, handlers ...web.Handler)

Get defines an endpoint for GET

func (*Service) GetCrons

func (s *Service) GetCrons() []*Cron

GetCrons returns a list of queues defined in the service

func (*Service) GetQueues

func (s *Service) GetQueues() []*taskqueue.PushQueue

GetQueues returns a list of queues defined in the service

func (*Service) GetTasks

func (s *Service) GetTasks() []*Task

GetTasks returns a list of queues defined in the service

func (*Service) Key

func (s *Service) Key() string

Key returns a key string

func (*Service) Namespace

func (s *Service) Namespace() string

Namespace returns a namespace string

func (*Service) Page

func (s *Service) Page(path string, p view.Page)

Page defines an endpoint for view.Page interaface

func (*Service) Path

func (s *Service) Path(p string) string

Path returns an absolute path for this s.

func (*Service) Post

func (s *Service) Post(path string, handlers ...web.Handler)

Post defines an endpoint for POST

func (*Service) Put

func (s *Service) Put(path string, handlers ...web.Handler)

Put defines an endpoint for PUT

func (*Service) Run

func (s *Service) Run()

Run register the service on http.Hander

func (*Service) RunTask

func (s *Service) RunTask(ctx context.Context, path string, params url.Values) (*asynctask.TaskStatus, error)

func (*Service) ServeHTTP

func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler#ServeHTTP

func (*Service) URLPrefix

func (s *Service) URLPrefix() string

URLPrefix returns a url prefix string

func (*Service) Use

func (s *Service) Use(handlers ...web.Handler)

Use adds the middleware onto the service router

func (*Service) WithNamespace

func (s *Service) WithNamespace(ctx context.Context) context.Context

WithNamespace sets the namespace of the given context

type Task

type Task struct {
	Path        string `json:"path"`
	Key         string `json:"key"`
	Description string `json:"description"`
	Schedule    string `json:"schedule"`
	// contains filtered or unexported fields
}

Task is a defined task in the service.

Directories

Path Synopsis
Package asynctask provides async task execution support on GAE apps
Package asynctask provides async task execution support on GAE apps

Jump to

Keyboard shortcuts

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